db timestamp guards (#70)

This commit is contained in:
Jim authored and GitHub committed 2020-05-27 17:35:04 -04:00
1 parent 6dd083fa42
commit aa64579a8c
11 files changed
+820 -150

No files matched your search

+69 -12
View File
@@ -2,33 +2,90 @@ begin;
-- create test tables used in the unit tests for the internal/db package
-- these tables (db_test_user, db_test_car, db_test_rental) are not part
-- of the Watchtower domain model... they are simply used for testing the internal/db package
CREATE TABLE if not exists db_test_user (
-- of the watchtower domain model... they are simply used for testing the internal/db package
create table if not exists db_test_user (
id bigint generated always as identity primary key,
create_time wt_timestamp,
update_time wt_timestamp,
public_id text NOT NULL UNIQUE,
name text UNIQUE,
public_id text not null unique,
name text unique,
phone_number text,
email text
);
CREATE TABLE if not exists db_test_car (
create trigger
update_time_column
before
update on db_test_user
for each row execute procedure update_time_column();
create trigger
create_time_column
before
update on db_test_user
for each row execute procedure immutable_create_time_func();
create trigger
default_create_time_column
before
insert on db_test_user
for each row execute procedure default_create_time();
create table if not exists db_test_car (
id bigint generated always as identity primary key,
create_time wt_timestamp,
update_time wt_timestamp,
public_id text NOT NULL UNIQUE,
name text UNIQUE,
public_id text not null unique,
name text unique,
model text,
mpg smallint
);
CREATE TABLE if not exists db_test_rental (
create trigger
update_time_column
before
update on db_test_car
for each row execute procedure update_time_column();
create trigger
create_time_column
before
update on db_test_car
for each row execute procedure immutable_create_time_func();
create trigger
default_create_time_column
before
insert on db_test_car
for each row execute procedure default_create_time();
create table if not exists db_test_rental (
id bigint generated always as identity primary key,
create_time wt_timestamp,
update_time wt_timestamp,
public_id text NOT NULL UNIQUE,
name text UNIQUE,
user_id bigint not null REFERENCES db_test_user(id),
car_id bigint not null REFERENCES db_test_car(id)
public_id text not null unique,
name text unique,
user_id bigint not null references db_test_user(id),
car_id bigint not null references db_test_car(id)
);
create trigger
update_time_column
before
update on db_test_rental
for each row execute procedure update_time_column();
create trigger
create_time_column
before
update on db_test_rental
for each row execute procedure immutable_create_time_func();
create trigger
default_create_time_column
before
insert on db_test_rental
for each row execute procedure default_create_time();
commit;