basic internal db interfaces and Gorm implementation
* db reader and writer interfaces which should allow us to encapsulate the vast majority of database code in this package. * GormReadWriter implementation of the Reader and Writer interfaces
This commit is contained in:
15 files changed
+2510
No files matched your search
@@ -0,0 +1,39 @@
|
||||
CREATE TABLE if not exists oplog_entry (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
version text NOT NULL,
|
||||
aggregate_name text NOT NULL,
|
||||
"data" bytea NOT NULL
|
||||
);
|
||||
CREATE TABLE if not exists oplog_ticket (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
"name" text NOT NULL UNIQUE,
|
||||
"version" bigint NOT NULL
|
||||
);
|
||||
CREATE TABLE if not exists oplog_metadata (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
entry_id bigint NOT NULL REFERENCES oplog_entry(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
"key" text NOT NULL,
|
||||
value text NULL
|
||||
);
|
||||
create index if not exists idx_oplog_metatadata_key on oplog_metadata(key);
|
||||
create index if not exists idx_oplog_metatadata_value on oplog_metadata(value);
|
||||
INSERT INTO oplog_ticket (name, version)
|
||||
values
|
||||
('default', 1),
|
||||
('iam_scope', 1),
|
||||
('iam_user', 1),
|
||||
('iam_auth_method', 1),
|
||||
('iam_group', 1),
|
||||
('iam_group_member_user', 1),
|
||||
('iam_role', 1),
|
||||
('iam_role_grant', 1),
|
||||
('iam_role_group', 1),
|
||||
('iam_role_user', 1),
|
||||
('db_test_user', 1),
|
||||
('db_test_car', 1),
|
||||
('db_test_rental', 1);
|
||||
@@ -0,0 +1,3 @@
|
||||
drop table if exists db_test_user;
|
||||
drop table if exists db_test_car;
|
||||
drop table if exists db_test_rental;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- 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 (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
name text,
|
||||
phone_number text,
|
||||
email text
|
||||
);
|
||||
CREATE TABLE if not exists db_test_car (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
model text,
|
||||
mpg smallint
|
||||
);
|
||||
CREATE TABLE if not exists db_test_rental (
|
||||
id bigint generated always as identity primary key,
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
user_id bigint not null REFERENCES db_test_user(id),
|
||||
car_id bigint not null REFERENCES db_test_car(id)
|
||||
);
|
||||
Reference in new issue
Block a user