Add missing SQL migration files
This commit is contained in:
parent
7754bfaae5
commit
fe65921ac0
2 changed files with 24 additions and 0 deletions
7
db/src/main/resources/sql/1.sql
Normal file
7
db/src/main/resources/sql/1.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE IF NOT EXISTS budgets (id TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT DEFAULT NULL, currency_code TEXT DEFAULT NULL);
|
||||
CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL, email TEXT DEFAULT NULL UNIQUE);
|
||||
CREATE TABLE IF NOT EXISTS categories (id TEXT PRIMARY KEY, title TEXT NOT NULL, description TEXT DEFAULT NULL, amount INTEGER NOT NULL, expense BOOLEAN NOT NULL, archived BOOLEAN NOT NULL, budget_id TEXT NOT NULL, CONSTRAINT fk_budgets FOREIGN KEY (budget_id) REFERENCES budgets (id) ON DELETE CASCADE);
|
||||
CREATE TABLE IF NOT EXISTS sessions (id TEXT PRIMARY KEY, user_id TEXT NOT NULL, token TEXT NOT NULL, expiration TIMESTAMP NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS user_permissions ( budget_id TEXT NOT NULL, user_id TEXT NOT NULL, permission TEXT NOT NULL, PRIMARY KEY (budget_id, user_id), CONSTRAINT fk_budgets FOREIGN KEY (budget_id) REFERENCES budgets (id) ON DELETE CASCADE, CONSTRAINT fk_users FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE);
|
||||
CREATE TABLE IF NOT EXISTS transactions (id TEXT PRIMARY KEY, title TEXT NOT NULL, description TEXT DEFAULT NULL, amount INTEGER NOT NULL, date TIMESTAMP NOT NULL, expense BOOLEAN NOT NULL, created_by TEXT NOT NULL, category_id TEXT DEFAULT NULL, budget_id TEXT NOT NULL, CONSTRAINT fk_users FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE CASCADE, CONSTRAINT fk_categories FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE, CONSTRAINT fk_budgets FOREIGN KEY (budget_id) REFERENCES budgets (id) ON DELETE CASCADE);
|
||||
CREATE TABLE IF NOT EXISTS twigs_metadata (version INTEGER NOT NULL, salt VARCHAR(16) NOT NULL);
|
17
db/src/main/resources/sql/2.sql
Normal file
17
db/src/main/resources/sql/2.sql
Normal file
|
@ -0,0 +1,17 @@
|
|||
CREATE TABLE IF NOT EXISTS recurring_transactions (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
frequency TEXT NOT NULL,
|
||||
start TIMESTAMP NOT NULL,
|
||||
finish TIMESTAMP,
|
||||
last_run TIMESTAMP,
|
||||
expense BOOLEAN NOT NULL,
|
||||
created_by TEXT NOT NULL,
|
||||
category_id TEXT DEFAULT NULL,
|
||||
budget_id TEXT NOT NULL,
|
||||
CONSTRAINT fk_users FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_categories FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_budgets FOREIGN KEY (budget_id) REFERENCES budgets (id) ON DELETE CASCADE
|
||||
);
|
Loading…
Reference in a new issue