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(