mirror of
https://github.com/acedanger/budget-database.git
synced 2025-12-05 22:50:13 -08:00
refactor SQL scripts for consistency and style improvements
This commit is contained in:
@@ -1,25 +1,38 @@
|
||||
drop table if exists public.accounts cascade;
|
||||
|
||||
CREATE TABLE public.accounts(
|
||||
acct_id serial,
|
||||
acct_bank_name varchar(50) not null,
|
||||
acct_type varchar(50) not null,
|
||||
acct_number varchar(20) null,
|
||||
acct_friendly_name varchar(50) null,
|
||||
insert_dt_tm timestamp null default now(),
|
||||
PRIMARY KEY( acct_id )
|
||||
create table public.accounts (
|
||||
acct_id serial,
|
||||
acct_bank_name varchar(50) not null,
|
||||
acct_type varchar(50) not null,
|
||||
acct_number varchar(20) null,
|
||||
acct_friendly_name varchar(50) null,
|
||||
created_at timestamp null default now(),
|
||||
primary key (acct_id)
|
||||
);
|
||||
|
||||
-- Permissions
|
||||
alter table public.accounts OWNER to acedanger;
|
||||
|
||||
ALTER TABLE public.accounts OWNER TO acedanger;
|
||||
GRANT ALL ON TABLE public.accounts TO acedanger;
|
||||
GRANT ALL ON TABLE public.accounts TO budgetuser;
|
||||
grant all on table public.accounts to acedanger;
|
||||
|
||||
grant all on table public.accounts to budgetuser;
|
||||
|
||||
-- Populate table
|
||||
truncate public.accounts;
|
||||
|
||||
INSERT INTO public.accounts (bank_name, account_type, friendly_name, account_number) values
|
||||
('Bank of America', 'Checking', 'Joint Checking', '4581')
|
||||
, ('Ally', 'Savings', 'Joint Savings', '9969')
|
||||
, ('Ally', 'Savings', 'Vacation Savings', '6268')
|
||||
insert into
|
||||
public.accounts (
|
||||
bank_name,
|
||||
account_type,
|
||||
friendly_name,
|
||||
account_number
|
||||
)
|
||||
values
|
||||
(
|
||||
'Bank of America',
|
||||
'Checking',
|
||||
'Joint Checking',
|
||||
'4581'
|
||||
),
|
||||
('Ally', 'Savings', 'Joint Savings', '9969'),
|
||||
('Ally', 'Savings', 'Vacation Savings', '6268')
|
||||
@@ -1,21 +1,19 @@
|
||||
-- public.budgetdetails definition
|
||||
|
||||
-- Drop table
|
||||
DROP table if exists public.budgetdetails cascade;
|
||||
drop table if exists public.budgetdetails cascade;
|
||||
|
||||
CREATE TABLE public.budgetdetails (
|
||||
trx_id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
trx_description text NOT NULL,
|
||||
trx_date date NOT NULL,
|
||||
trx_amount numeric NOT NULL,
|
||||
acct_id int NULL,
|
||||
insert_dt_tm timestamp NULL DEFAULT now(),
|
||||
primary key ( trx_id ),
|
||||
constraint fk_acct foreign key ( acct_id ) references public.accounts(acct_id) on delete set null
|
||||
create table public.budgetdetails (
|
||||
trx_id uuid not null default uuid_generate_v4 (),
|
||||
trx_description text not null,
|
||||
trx_date date not null,
|
||||
trx_amount numeric not null,
|
||||
acct_id int null,
|
||||
created_at timestamp null default now(),
|
||||
primary key (trx_id),
|
||||
constraint fk_acct foreign key (acct_id) references public.accounts (acct_id) on delete set null
|
||||
);
|
||||
|
||||
-- Permissions
|
||||
|
||||
ALTER TABLE public.budgetdetails OWNER TO acedanger;
|
||||
GRANT ALL ON TABLE public.budgetdetails TO acedanger;
|
||||
GRANT ALL ON TABLE public.budgetdetails TO budgetuser;
|
||||
alter table public.budgetdetails OWNER to acedanger;
|
||||
grant all on table public.budgetdetails to acedanger;
|
||||
grant all on table public.budgetdetails to budgetuser;
|
||||
@@ -1,11 +1,13 @@
|
||||
DROP TABLE public.budgetimport;
|
||||
drop table public.budgetimport;
|
||||
|
||||
create table public.budgetimport (
|
||||
dt bpchar(20) NULL,
|
||||
amount numeric(10, 2) NULL,
|
||||
description bpchar(200) NULL
|
||||
dt bpchar (20) null,
|
||||
amount numeric(10, 2) null,
|
||||
description bpchar (200) null
|
||||
);
|
||||
|
||||
ALTER TABLE public.budgetimport OWNER TO acedanger;
|
||||
GRANT ALL ON TABLE public.budgetimport TO acedanger;
|
||||
GRANT ALL ON TABLE public.budgetimport TO budgetuser;
|
||||
alter table public.budgetimport OWNER to acedanger;
|
||||
|
||||
grant all on table public.budgetimport to acedanger;
|
||||
|
||||
grant all on table public.budgetimport to budgetuser;
|
||||
Reference in New Issue
Block a user