From 5f1591c8565c878499fe164f777fda92a2287ba0 Mon Sep 17 00:00:00 2001 From: jethro Date: Wed, 13 May 2026 19:06:21 +1200 Subject: [PATCH] fixed syntax for foreign keys --- sql/database definitions.sql | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sql/database definitions.sql b/sql/database definitions.sql index 6599832..3941c76 100644 --- a/sql/database definitions.sql +++ b/sql/database definitions.sql @@ -2,7 +2,7 @@ CREATE table IF NOT EXISTS accounts( id SERIAL PRIMARY KEY, accountnum VARCHAR UNIQUE NOT NULL, accountname VARCHAR UNIQUE NOT NULL, -orgid int -- this needs to be a foregn key on organizations +REFERENCES organizations(id) ON DELETE SET NULL ); CREATE TABLE IF NOT EXISTS organizations( @@ -15,28 +15,29 @@ id SERIAL PRIMARY KEY, datetime DATE NOT NULL, description VARCHAR NOT NULL, amount REAL NOT NULL, -accountid INT NOT NULL --foreign key from accounts -orgid INT NOT NULL --foreign key from organizations +accountid INT NOT NULL REFERENCES accounts(id) ON DELETE SET NULL, +orgid INT NOT NULL REFERENCES organizations(id) ON DELETE SET NULL ) CREATE TABLE IF NOT EXISTS snapshots( id SERIAL PRIMARY KEY, datetime DATE NOT NULL, -accountid INT NOT NULL, --foreign key from accounts +accountid INT NOT NULL REFERENCES accounts(id) ON DELETE SET NULL, balance REAL NOT NULL, -orgid INT NOT NULL --foreign key from organizations +orgid INT NOT NULL REFERENCES organizations(id) ON DELETE SET NULL ) CREATE TABLE IF NOT EXISTS syncs( id SERIAL PRIMARY KEY, datetime DATE NOT NULL, -accountid INT NOT NULL, --foreign key from accounts -orgid INT NOT NULL --foreign key from organizations +accountid INT NOT NULL REFERENCES accounts(id) ON DELETE SET NULL, +orgid INT NOT NULL REFERENCES organizations(id) ON DELETE SET NULL ) CREATE TABLE IF NOT EXISTS vendors( id SERIAL PRIMARY KEY, vendorname VARCHAR NOT NULL, +orgid INT NOT NULL REFERENCES organizations(id) ON DELETE SET NULL ) CREATE TABLE IF NOT EXISTS rawtransactions(