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,12 +2,12 @@ import sqlite3 from 'sqlite3';
|
|||
|
||||
function migrate_0_1(db: sqlite3.Database) {
|
||||
db.serialize(() => {
|
||||
`
|
||||
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 (
|
||||
|
@ -22,10 +22,10 @@ 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 (
|
||||
|
@ -33,7 +33,7 @@ function migrate_0_1(db: sqlite3.Database) {
|
|||
date DATETIME DEFAULT NULL,
|
||||
token TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
FOREIGN KEY user_id REFERENCES user(id)
|
||||
FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
);
|
||||
|
||||
CREATE TABLE session (
|
||||
|
@ -41,10 +41,10 @@ function migrate_0_1(db: sqlite3.Database) {
|
|||
user_id TEXT NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
expiration date NOT NULL,
|
||||
FOREIGN KEY user_id REFERENCES user(id)
|
||||
FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
);
|
||||
|
||||
CREATE TABLE transaction (
|
||||
CREATE TABLE 'transaction' (
|
||||
id TEXT PRIMARY KEY,
|
||||
amount UNSIGNED BIG INT NOT NULL,
|
||||
date DATETIME NOT NULL,
|
||||
|
@ -54,9 +54,9 @@ function migrate_0_1(db: sqlite3.Database) {
|
|||
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)
|
||||
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 (
|
||||
|
@ -64,9 +64,10 @@ function migrate_0_1(db: sqlite3.Database) {
|
|||
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)
|
||||
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