Fix sqlite migration 0-1 syntax
This commit is contained in:
parent
4643f00e15
commit
31af400281
1 changed files with 48 additions and 47 deletions
|
@ -2,19 +2,19 @@ import sqlite3 from 'sqlite3';
|
|||
|
||||
function migrate_0_1(db: sqlite3.Database) {
|
||||
db.serialize(() => {
|
||||
`
|
||||
CREATE TABLE user (
|
||||
db.run(`
|
||||
CREATE TABLE user (
|
||||
id TEXT PRIMARY KEY,
|
||||
email TEXT DEFAULT NULL,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL,
|
||||
password TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE budget (
|
||||
id TEXT PRIMARY KEY,
|
||||
currency_code TEXT DEFAULT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
name TEXT DEFAULT NULL
|
||||
id TEXT PRIMARY KEY,
|
||||
currency_code TEXT DEFAULT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
name TEXT DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE category (
|
||||
|
@ -22,51 +22,52 @@ function migrate_0_1(db: sqlite3.Database) {
|
|||
amount UNSIGNED BIG INT NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
expense BOOLEAN NOT NULL DEFAULT 0,
|
||||
title TEXT DEFAULT NULL,
|
||||
budget_id TEXT DEFAULT NULL,
|
||||
title TEXT NOT NULL,
|
||||
budget_id TEXT NOT NULL,
|
||||
archived BOOLEAN NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY budget_id REFERENCES budget(id)
|
||||
FOREIGN KEY (budget_id) REFERENCES budget(id)
|
||||
);
|
||||
|
||||
CREATE TABLE password_reset_request (
|
||||
id TEXT PRIMARY KEY,
|
||||
date DATETIME DEFAULT NULL,
|
||||
token TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
FOREIGN KEY user_id REFERENCES user(id)
|
||||
);
|
||||
CREATE TABLE password_reset_request (
|
||||
id TEXT PRIMARY KEY,
|
||||
date DATETIME DEFAULT NULL,
|
||||
token TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
);
|
||||
|
||||
CREATE TABLE session (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
expiration date NOT NULL,
|
||||
FOREIGN KEY user_id REFERENCES user(id)
|
||||
);
|
||||
CREATE TABLE session (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
expiration date NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
);
|
||||
|
||||
CREATE TABLE transaction (
|
||||
id TEXT PRIMARY KEY,
|
||||
amount UNSIGNED BIG INT NOT NULL,
|
||||
date DATETIME NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
expense BOOLEAN NOT NULL,
|
||||
title TEXT DEFAULT NULL,
|
||||
budget_id TEXT NOT NULL,
|
||||
category_id TEXT DEFAULT NULL,
|
||||
created_by_id TEXT NOT NULL,
|
||||
FOREIGN KEY budget_id REFERENCES budget(id),
|
||||
FOREIGN KEY category_id REFERENCES category(id),
|
||||
FOREIGN KEY created_by_id REFERENCES user(id)
|
||||
);
|
||||
CREATE TABLE 'transaction' (
|
||||
id TEXT PRIMARY KEY,
|
||||
amount UNSIGNED BIG INT NOT NULL,
|
||||
date DATETIME NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
expense BOOLEAN NOT NULL,
|
||||
title TEXT DEFAULT NULL,
|
||||
budget_id TEXT NOT NULL,
|
||||
category_id TEXT DEFAULT NULL,
|
||||
created_by_id TEXT NOT NULL,
|
||||
FOREIGN KEY (budget_id) REFERENCES budget(id),
|
||||
FOREIGN KEY (category_id) REFERENCES category(id),
|
||||
FOREIGN KEY (created_by_id) REFERENCES user(id)
|
||||
);
|
||||
|
||||
CREATE TABLE user_permission (
|
||||
budget_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
permission TEXT DEFAULT NULL,
|
||||
PRIMARY KEY (budget_id,user_id),
|
||||
FOREIGN KEY budget_id REFERENCES budget(id),
|
||||
FOREIGN KEY created_by_id REFERENCES user(id)
|
||||
);
|
||||
`
|
||||
CREATE TABLE user_permission (
|
||||
budget_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
permission TEXT DEFAULT NULL,
|
||||
PRIMARY KEY (budget_id,user_id),
|
||||
FOREIGN KEY (budget_id) REFERENCES budget(id),
|
||||
FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
);
|
||||
`);
|
||||
db.run('PRAGMA user_version = 1');
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue