fixed syntax for foreign keys

This commit is contained in:
jethro 2026-05-13 19:06:21 +12:00
parent c06e926627
commit 5f1591c856

View file

@ -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(