bliss/migrations/000_bootstrap_db.sql

63 lines
1.7 KiB
MySQL
Raw Normal View History

2024-02-03 13:22:50 -05:00
CREATE TABLE users (
2024-02-24 11:12:14 -05:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
password TEXT NOT NULL,
UNIQUE(username)
2024-02-03 13:22:50 -05:00
);
CREATE TABLE structures (
2024-02-24 11:12:14 -05:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
2024-02-03 13:22:50 -05:00
name TEXT NOT NULL,
user_id INTEGER,
2024-02-24 11:12:14 -05:00
FOREIGN KEY(user_id) REFERENCES users(id),
UNIQUE(name, user_id)
2024-02-03 13:22:50 -05:00
);
CREATE TABLE dbs (
2024-02-24 11:12:14 -05:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
2024-02-03 13:22:50 -05:00
name TEXT NOT NULL,
belongs_to_struct INTEGER,
2024-02-24 11:12:14 -05:00
FOREIGN KEY(belongs_to_struct) REFERENCES structures(id),
UNIQUE(name, belongs_to_struct)
2024-02-03 13:22:50 -05:00
);
CREATE TABLE templates (
2024-02-24 11:12:14 -05:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT NOT NULL,
2024-02-03 13:22:50 -05:00
user_id INTEGER,
belongs_to_struct INTEGER,
2024-02-24 11:12:14 -05:00
engine TEXT NOT NULL,
FOREIGN KEY(user_id) REFERENCES users(id),
FOREIGN KEY(belongs_to_struct) REFERENCES structures(id),
UNIQUE(name, belongs_to_struct)
2024-02-03 13:22:50 -05:00
);
2024-02-24 11:12:14 -05:00
2024-02-03 13:22:50 -05:00
CREATE TABLE routes (
2024-02-24 11:12:14 -05:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
2024-02-03 13:22:50 -05:00
verb TEXT CHECK(verb IN ('POST', 'GET', 'PUT', 'DELETE')),
path TEXT NOT NULL,
structure_id INTEGER,
user_id INTEGER,
handler TEXT NOT NULL,
2024-02-24 11:12:14 -05:00
language TEXT NOT NULL,
FOREIGN KEY(structure_id) REFERENCES structures(id),
FOREIGN KEY(user_id) REFERENCES users(id) UNIQUE(verb, path)
2024-02-03 13:22:50 -05:00
);
2024-02-24 11:12:14 -05:00
2024-02-03 13:22:50 -05:00
CREATE TABLE structure_dbs (
db_id INTEGER,
structure_id INTEGER,
PRIMARY KEY(db_id, structure_id),
2024-02-24 11:12:14 -05:00
FOREIGN KEY(db_id) REFERENCES dbs(id),
FOREIGN KEY(structure_id) REFERENCES structures(id)
2024-02-03 13:22:50 -05:00
);
2024-02-24 11:12:14 -05:00
2024-02-03 13:22:50 -05:00
CREATE TABLE structure_templates (
template_id INTEGER,
structure_id INTEGER,
2024-02-24 11:12:14 -05:00
alias TEXT NOT NULL,
2024-02-03 13:22:50 -05:00
PRIMARY KEY(template_id, structure_id),
2024-02-24 11:12:14 -05:00
FOREIGN KEY(template_id) REFERENCES templates(id),
FOREIGN KEY(structure_id) REFERENCES structures(id),
UNIQUE(structure_id, alias)
);