fixed test sql code errors
This commit is contained in:
parent
e96e9b033d
commit
bf31a1c7a8
2 changed files with 29 additions and 31 deletions
0
test.db
0
test.db
|
@ -20,59 +20,57 @@ func Init_testdb(DB_TYPE string, DB_CONNECTION_STRING string) {
|
|||
init_sql := `
|
||||
|
||||
CREATE TABLE accounts (
|
||||
acnt_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
acnt_id Integer PRIMARY KEY,
|
||||
acnt_dsply_name varchar(50) NOT NULL,
|
||||
acnt_description varchar(250) NULL,
|
||||
CONSTRAINT accounts_pkey PRIMARY KEY (acnt_id)
|
||||
acnt_description varchar(250) NULL
|
||||
);
|
||||
|
||||
CREATE TABLE buckets (
|
||||
bkt_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
bkt_id Integer PRIMARY KEY,
|
||||
bkt_dsply_code varchar(5) NOT NULL,
|
||||
bkt_dsply_name varchar(50) NULL,
|
||||
bkt_description varchar(250) NULL,
|
||||
CONSTRAINT buckets_pkey PRIMARY KEY (bkt_id)
|
||||
bkt_description varchar(250) NULL
|
||||
);
|
||||
|
||||
CREATE TABLE transaction_breakdown (
|
||||
trns_brkdwn_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
trns_brkdwn_amount money NOT NULL,
|
||||
trns_brkdwn_parent_transaction int4 NOT NULL,
|
||||
trns_brkdwn_catagory int4 NULL,
|
||||
trns_brkdwn_bucket int4 NULL,
|
||||
CONSTRAINT transaction_breakdown_pkey PRIMARY KEY (trns_brkdwn_id)
|
||||
);
|
||||
|
||||
alter table transaction_breakdown add constraint transaction_breakdown_parent_transaction_fkey foreign key (trns_brkdwn_parent_transaction) references transactions(trns_id);
|
||||
alter table transaction_breakdown add constraint transaction_breakdown_catagory_fkey foreign key (trns_brkdwn_catagory) references transaction_categories(trns_ctgry_id);
|
||||
alter table transaction_breakdown add constraint transaction_breakdown_bucket_fkey foreign key (trns_brkdwn_bucket) references buckets(bkt_id);
|
||||
|
||||
CREATE TABLE transactions (
|
||||
trns_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
trns_id Integer PRIMARY KEY,
|
||||
trns_amount money NOT NULL,
|
||||
trns_description varchar(250) NULL,
|
||||
trns_account int4 NOT NULL,
|
||||
trns_bucket int4 NULL,
|
||||
trns_date Date not null,
|
||||
CONSTRAINT transactions_pkey PRIMARY KEY (trns_id)
|
||||
FOREIGN KEY (trns_account)
|
||||
REFERENCES accounts (acnt_id)
|
||||
ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
FOREIGN KEY (trns_bucket)
|
||||
REFERENCES buckets (bkt_id)
|
||||
ON UPDATE CASCADE ON DELETE SET NULL
|
||||
);
|
||||
|
||||
ALTER TABLE transactions ADD CONSTRAINT transactions_trns_account_fkey FOREIGN KEY (trns_account) REFERENCES accounts(acnt_id);
|
||||
ALTER TABLE transactions ADD CONSTRAINT transactions_trns_bucket_fkey FOREIGN KEY (trns_bucket) REFERENCES buckets(bkt_id) ON DELETE SET NULL;
|
||||
CREATE TABLE transaction_breakdown (
|
||||
trns_brkdwn_id Integer PRIMARY KEY,
|
||||
trns_brkdwn_amount money NOT NULL,
|
||||
trns_brkdwn_parent_transaction int4 NOT NULL,
|
||||
trns_brkdwn_catagory int4 NULL,
|
||||
trns_brkdwn_bucket int4 NULL,
|
||||
FOREIGN KEY (trns_brkdwn_parent_transaction)
|
||||
REFERENCES transactions (trns_id)
|
||||
ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
FOREIGN KEY (trns_brkdwn_catagory)
|
||||
REFERENCES transaction_categories(trns_ctgry_id)
|
||||
ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
FOREIGN KEY (trns_brkdwn_bucket)
|
||||
REFERENCES buckets (bkt_id)
|
||||
ON UPDATE CASCADE ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE TABLE transaction_categories (
|
||||
trns_ctgry_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
trns_ctgry_id Integer PRIMARY KEY,
|
||||
trns_ctgry_dsply_code varchar(5) NOT NULL,
|
||||
trns_ctgry_dsply_name varchar(50) NOT NULL,
|
||||
trns_ctgry_description varchar(250) NULL,
|
||||
CONSTRAINT transaction_categories_pkey PRIMARY KEY (trns_ctgry_id)
|
||||
trns_ctgry_description varchar(250) NULL
|
||||
);
|
||||
|
||||
-- transaction_breakdown foreign keys
|
||||
|
||||
ALTER TABLE transaction_breakdown ADD CONSTRAINT transaction_breakdown_trns_brkdwn_catagory_fkey FOREIGN KEY (trns_brkdwn_catagory) REFERENCES transaction_categories(trns_ctgry_id) ON DELETE SET NULL;
|
||||
ALTER TABLE transaction_breakdown ADD CONSTRAINT transaction_breakdown_trns_brkdwn_parent_transaction_fkey FOREIGN KEY (trns_brkdwn_parent_transaction) REFERENCES transactions(trns_id) ON DELETE CASCADE;
|
||||
ALTER TABLE transaction_breakdown ADD CONSTRAINT transaction_breakdown_trns_brkdwn_bucket_fkey FOREIGN KEY (trns_brkdwn_bucket) REFERENCES buckets(bkt_id) ON DELETE SET NULL;
|
||||
`
|
||||
|
||||
tx := db.MustBegin()
|
||||
|
|
Loading…
Reference in a new issue