From ede83f905046e1e9556d46a029f1b56c3642faf9 Mon Sep 17 00:00:00 2001 From: Makussu Date: Thu, 6 Jun 2024 20:57:54 +0200 Subject: [PATCH] readme and bootstrap --- dependencies.js | 54 +++++++++++++++++++++++++------------------------ readme.md | 2 ++ readme.org | 2 -- 3 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 readme.md delete mode 100644 readme.org diff --git a/dependencies.js b/dependencies.js index 44888a3..cfa5d3d 100644 --- a/dependencies.js +++ b/dependencies.js @@ -5,6 +5,34 @@ const databaseFile = "mytest.db" fs.readFile(databaseFile, (err, data) => { if (err) { fs.openSync(databaseFile, 'w'); + const db = require('better-sqlite3')(databaseFile); + // Bootstrap the db + db.exec(` + CREATE TABLE IF NOT EXISTS accounts ( + number integer NOT NULL, + name text NOT NULL, + qualifiedName text NOT NULL UNIQUE, + parentAccount text, + description text NOT NULL, + type TEXT NOT NULL + ); + + CREATE TABLE IF NOT EXISTS transactions ( + transaction_id integer PRIMARY KEY, + postingDate text NOT NULL, + valueDate text, + title text NOT NULL + ); + + CREATE TABLE IF NOT EXISTS transaction_entries ( + transaction_id int, + account_name text NOT NULL, + amount float, + label text, + FOREIGN KEY (transaction_id) REFERENCES transactions (transaction_id) FOREIGN KEY (account_name) REFERENCES accounts (qualifiedName) PRIMARY KEY (transaction_id, account_name) + ); +`) + create_initial_accounts() } }) @@ -42,32 +70,6 @@ function create_initial_accounts() { }); } -// Bootstrap the db -db.exec(` -CREATE TABLE IF NOT EXISTS accounts ( -number integer NOT NULL, -name text NOT NULL, -qualifiedName text NOT NULL UNIQUE, -parentAccount text, -description text NOT NULL, -type TEXT NOT NULL -); - -CREATE TABLE IF NOT EXISTS transactions ( -transaction_id integer PRIMARY KEY, -postingDate text NOT NULL, -valueDate text, -title text NOT NULL -); - -CREATE TABLE IF NOT EXISTS transaction_entries ( -transaction_id int, -account_name text NOT NULL, -amount float, -label text, -FOREIGN KEY (transaction_id) REFERENCES transactions (transaction_id) FOREIGN KEY (account_name) REFERENCES accounts (qualifiedName) PRIMARY KEY (transaction_id, account_name) -); -`) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4a88e20 --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +# Unser Backend + Frontend +Einfach starten mit `npm run run`. Database erstellt sich selber. diff --git a/readme.org b/readme.org deleted file mode 100644 index 8079935..0000000 --- a/readme.org +++ /dev/null @@ -1,2 +0,0 @@ -* TODO What is account.number? -id? wtf