diff --git a/deploy/invoice_number_counter.sql b/deploy/invoice_number_counter.sql index 2713e6b..07330ad 100644 --- a/deploy/invoice_number_counter.sql +++ b/deploy/invoice_number_counter.sql @@ -7,7 +7,7 @@ begin; set search_path to numerus, public; create table invoice_number_counter ( - company_id integer not null, + company_id integer not null references company, year integer not null constraint year_always_positive check(year > 0), currval integer not null constraint counter_zero_or_positive check(currval >= 0), primary key (company_id, year) diff --git a/test/invoice_number_counter.sql b/test/invoice_number_counter.sql index a2dd262..955c7a0 100644 --- a/test/invoice_number_counter.sql +++ b/test/invoice_number_counter.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(25); +select plan(27); set search_path to numerus, auth, public; @@ -19,6 +19,8 @@ select table_privs_are('invoice_number_counter', 'admin', array ['SELECT', 'INSE select table_privs_are('invoice_number_counter', 'authenticator', array []::text[]); select has_column('invoice_number_counter', 'company_id'); +select col_is_fk('invoice_number_counter', 'company_id'); +select fk_ok('invoice_number_counter', 'company_id', 'company', 'company_id'); select col_type_is('invoice_number_counter', 'company_id', 'integer'); select col_not_null('invoice_number_counter', 'company_id'); select col_hasnt_default('invoice_number_counter', 'company_id'); @@ -66,11 +68,6 @@ values (2, 1) , (4, 5) ; -insert into contact (contact_id, company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code) -values (6, 2, 'Contact 1', 'XX555', '', '777-777-777', 'c@c', '', '', '', '', '', 'ES') - , (8, 4, 'Contact 2', 'XX666', '', '888-888-888', 'd@d', '', '', '', '', '', 'ES') -; - insert into invoice_number_counter (company_id, year, currval) values (2, 2010, 6) , (2, 2011, 8)