Bootstrap the Application
This commit is contained in:
parent
60f3c29717
commit
01e2fd63f5
@ -1,4 +1,40 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const databaseFile = "mytest.db"
|
||||||
|
|
||||||
|
fs.readFile(databaseFile, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
fs.openSync(databaseFile, 'w');
|
||||||
|
}
|
||||||
|
})
|
||||||
// DB
|
// DB
|
||||||
const db = require('better-sqlite3')('mytest.db');
|
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)
|
||||||
|
);
|
||||||
|
`)
|
||||||
|
|
||||||
module.exports = db
|
module.exports = db
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
CREATE TABLE accounts (
|
CREATE TABLE IF NOT EXISTS accounts (
|
||||||
number integer NOT NULL,
|
number integer NOT NULL,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
qualifiedName text NOT NULL UNIQUE,
|
qualifiedName text NOT NULL UNIQUE,
|
||||||
@ -7,14 +7,14 @@ CREATE TABLE accounts (
|
|||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE transactions (
|
CREATE TABLE IF NOT EXISTS transactions (
|
||||||
transaction_id integer PRIMARY KEY,
|
transaction_id integer PRIMARY KEY,
|
||||||
postingDate text NOT NULL,
|
postingDate text NOT NULL,
|
||||||
valueDate text,
|
valueDate text,
|
||||||
title text NOT NULL
|
title text NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE transaction_entries (
|
CREATE TABLE IF NOT EXISTS transaction_entries (
|
||||||
transaction_id int,
|
transaction_id int,
|
||||||
account_name text NOT NULL,
|
account_name text NOT NULL,
|
||||||
amount float,
|
amount float,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user