wow
This commit is contained in:
parent
e335c65506
commit
23414c7b66
490 changed files with 340402 additions and 93 deletions
|
|
@ -2,6 +2,8 @@ CREATE TABLE users (
|
|||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
|
|
@ -9,6 +11,8 @@ CREATE TABLE structures (
|
|||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
user_id INTEGER,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id),
|
||||
UNIQUE(name, user_id)
|
||||
);
|
||||
|
|
@ -16,48 +20,84 @@ CREATE TABLE structures (
|
|||
CREATE TABLE dbs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
belongs_to_struct INTEGER,
|
||||
FOREIGN KEY(belongs_to_struct) REFERENCES structures(id),
|
||||
UNIQUE(name, belongs_to_struct)
|
||||
structure_id INTEGER,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
library TEXT NOT NULL DEFAULT "",
|
||||
FOREIGN KEY(structure_id) REFERENCES structures(id),
|
||||
UNIQUE(name, structure_id)
|
||||
);
|
||||
|
||||
CREATE TABLE templates (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
file_path TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT,
|
||||
user_id INTEGER,
|
||||
belongs_to_struct INTEGER,
|
||||
engine TEXT NOT NULL,
|
||||
structure_id INTEGER,
|
||||
engine TEXT NOT NULL DEFAULT "eta",
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id),
|
||||
FOREIGN KEY(belongs_to_struct) REFERENCES structures(id),
|
||||
UNIQUE(name, belongs_to_struct)
|
||||
FOREIGN KEY(structure_id) REFERENCES structures(id)
|
||||
);
|
||||
|
||||
CREATE TABLE routes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
verb TEXT CHECK(verb IN ('POST', 'GET', 'PUT', 'DELETE')),
|
||||
verb TEXT CHECK(verb IN ('POST', 'GET', 'PUT', 'DELETE')) NOT NULL,
|
||||
path TEXT NOT NULL,
|
||||
structure_id INTEGER,
|
||||
user_id INTEGER,
|
||||
handler TEXT NOT NULL,
|
||||
language TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(structure_id) REFERENCES structures(id),
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) UNIQUE(verb, path)
|
||||
UNIQUE(verb, path, structure_id)
|
||||
);
|
||||
|
||||
CREATE TABLE structure_dbs (
|
||||
db_id INTEGER,
|
||||
structure_id INTEGER,
|
||||
alias TEXT NOT NULL,
|
||||
PRIMARY KEY(db_id, structure_id),
|
||||
FOREIGN KEY(db_id) REFERENCES dbs(id),
|
||||
FOREIGN KEY(structure_id) REFERENCES structures(id)
|
||||
);
|
||||
|
||||
CREATE TABLE structure_templates (
|
||||
template_id INTEGER,
|
||||
structure_id INTEGER,
|
||||
alias TEXT NOT NULL,
|
||||
PRIMARY KEY(template_id, structure_id),
|
||||
FOREIGN KEY(template_id) REFERENCES templates(id),
|
||||
FOREIGN KEY(structure_id) REFERENCES structures(id),
|
||||
UNIQUE(structure_id, alias)
|
||||
);
|
||||
|
||||
-- ===========================
|
||||
-- TRIGGERS
|
||||
-- ===========================
|
||||
|
||||
CREATE TRIGGER update_users_updated_at
|
||||
AFTER UPDATE ON users
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE users SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER update_structures_updated_at
|
||||
AFTER UPDATE ON structures
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE structures SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER update_dbs_updated_at
|
||||
AFTER UPDATE ON dbs
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE dbs SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER update_templates_updated_at
|
||||
AFTER UPDATE ON templates
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE templates SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER update_routes_updated_at
|
||||
AFTER UPDATE ON routes
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE routes SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue