Initial import
This commit is contained in:
commit
1ff831f80d
19 changed files with 956 additions and 0 deletions
62
bin/create-dbix-class-schemas
Executable file
62
bin/create-dbix-class-schemas
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/bin/sh
|
||||
err()
|
||||
{
|
||||
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
warn()
|
||||
{
|
||||
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
||||
}
|
||||
|
||||
check_required_programs()
|
||||
{
|
||||
_rc=0
|
||||
for _prog; do
|
||||
if ! command -v "$_prog" >/dev/null; then
|
||||
_rc=1
|
||||
warn "$_prog: not found"
|
||||
fi
|
||||
done
|
||||
return $_rc;
|
||||
}
|
||||
|
||||
set -eu
|
||||
|
||||
check_required_programs sqlite3 dbicdump || exit 1
|
||||
|
||||
sqlite3 "db/PoorBooru.db" <<'_SQL'
|
||||
PRAGMA foreig_keys = ON;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS media(
|
||||
media_id INTEGER PRIMARY KEY,
|
||||
content BLOB (10485760) NOT NULL,
|
||||
filename TEXT (255) NOT NULL,
|
||||
content_type TEXT (255)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tags(
|
||||
tag_id INTEGER PRIMARY KEY,
|
||||
name TEXT (255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS media_tags(
|
||||
media_id INTEGER NOT NULL,
|
||||
tag_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (media_id) REFERENCES media (media_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (tag_id) REFERENCES tags (tag_id) ON DELETE CASCADE,
|
||||
PRIMARY KEY(media_id, tag_id)
|
||||
);
|
||||
|
||||
CREATE VIEW IF NOT EXISTS tags_count_view AS SELECT
|
||||
tags.tag_id AS tag_id,
|
||||
tags.name AS name,
|
||||
COUNT(media_tags.media_id) AS count
|
||||
FROM tags
|
||||
INNER JOIN media_tags USING (tag_id)
|
||||
GROUP BY tag_id;
|
||||
|
||||
_SQL
|
||||
|
||||
dbicdump -o dump_directory=./lib PoorBooru::Schema dbi:SQLite:db/PoorBooru.db
|
Reference in a new issue