From d479ff86090b66f16eae1464166f705eb4ab3420 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 21 Oct 2022 08:48:31 -0400 Subject: [PATCH] basic schema conversion for postgres (#46) --- controller/store/sql/postgresql/000_base.sql | 62 ++++++++++++++++++++ controller/store/sql/postgresql/embed.go | 6 ++ 2 files changed, 68 insertions(+) create mode 100644 controller/store/sql/postgresql/000_base.sql create mode 100644 controller/store/sql/postgresql/embed.go diff --git a/controller/store/sql/postgresql/000_base.sql b/controller/store/sql/postgresql/000_base.sql new file mode 100644 index 00000000..527401bc --- /dev/null +++ b/controller/store/sql/postgresql/000_base.sql @@ -0,0 +1,62 @@ +-- +migrate Up + +-- +-- accounts +-- +create table accounts ( + id integer primary key, + email varchar(1024) not null unique, + password char(128) not null, + token varchar(32) not null unique, + created_at timestamp not null default(current_timestamp), + updated_at timestamp not null default(current_timestamp), + + constraint chk_email check (email <> ''), + constraint chk_password check (password <> ''), + constraint chk_token check(token <> '') +); + +-- +-- account_requests +-- +create table account_requests ( + id integer primary key, + token varchar(32) not null unique, + email varchar(1024) not null unique, + source_address varchar(64) not null, + created_at timestamp not null default(current_timestamp), + updated_at timestamp not null default(current_timestamp) +); + +-- +-- environments +-- +create table environments ( + id integer primary key, + account_id integer constraint fk_accounts_identities references accounts on delete cascade, + description text, + host varchar(256), + address varchar(64), + z_id varchar(32) not null unique, + created_at timestamp not null default(current_timestamp), + updated_at timestamp not null default(current_timestamp), + + constraint chk_z_id check (z_id <> '') +); + +-- +-- services +-- +create table services ( + id integer primary key, + environment_id integer constraint fk_environments_services references environments on delete cascade, + z_id varchar(32) not null unique, + name varchar(32) not null unique, + frontend varchar(1024), + backend varchar(1024), + created_at timestamp not null default(current_timestamp), + updated_at timestamp not null default(current_timestamp), + + constraint chk_z_id check (z_id <> ''), + constraint chk_name check (name <> '') +); \ No newline at end of file diff --git a/controller/store/sql/postgresql/embed.go b/controller/store/sql/postgresql/embed.go new file mode 100644 index 00000000..3c272de8 --- /dev/null +++ b/controller/store/sql/postgresql/embed.go @@ -0,0 +1,6 @@ +package postgresql_schema + +import "embed" + +//go:embed *.sql +var FS embed.FS