diff --git a/db/migration/base/001.up.base.sql b/db/migration/base/001.up.base.sql index 2f8437e..7db5602 100644 --- a/db/migration/base/001.up.base.sql +++ b/db/migration/base/001.up.base.sql @@ -2,6 +2,9 @@ create domain dmn_code as text not null; create domain dmn_money as numeric(22, 4); create domain dmn_qty numeric(18, 6); create domain dmn_rate as numeric(5, 2); +create domain dmn_clid bigint not null check ( value > 0 ); +create domain dmn_usrid bigint not null check ( value > 0 ); + create function iif(condition boolean, true_result anyelement, false_result anyelement) returns anyelement immutable diff --git a/db/migration/base/002.up.company.sql b/db/migration/base/002.up.company.sql new file mode 100644 index 0000000..26f7a34 --- /dev/null +++ b/db/migration/base/002.up.company.sql @@ -0,0 +1,26 @@ +create table company ( + clid dmn_clid, + id bigint generated by default as identity PRIMARY key, + code dmn_code, + title text, + is_active boolean default true not null, + + notes text, + + zlins_dttm timestamptz, + zlupd_dttm timestamptz, + + constraint uq_company unique (clid, code) + ); + +CREATE TRIGGER zl_company before INSERT or UPDATE ON company + FOR EACH ROW EXECUTE FUNCTION zllog(); + +create table company_usr ( + id bigint generated by default as identity PRIMARY key, + company_id bigint not null, + usr_id dmn_usrid, + constraint uq_company_usr unique (company_id, usr_id), + constraint fk_company_usr_company foreign key (company_id) + references company(id) on update cascade on delete cascade + ); diff --git a/db/migration/base/003.up.company_tmpl.sql b/db/migration/base/003.up.company_tmpl.sql new file mode 100644 index 0000000..1748499 --- /dev/null +++ b/db/migration/base/003.up.company_tmpl.sql @@ -0,0 +1 @@ +alter table company add tmpl jsonb; \ No newline at end of file diff --git a/db/sqls/company.sql b/db/sqls/company.sql new file mode 100644 index 0000000..e69de29