(Feat): Initial Commit
This commit is contained in:
6
migrations/20200428064736-install-extension-uuid.sql
Normal file
6
migrations/20200428064736-install-extension-uuid.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- +migrate Up
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
-- +migrate Down
|
||||
DROP EXTENSION IF EXISTS "uuid-ossp";
|
||||
|
||||
9
migrations/20200428064802-create-user-scope-enum.sql
Normal file
9
migrations/20200428064802-create-user-scope-enum.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE user_scope AS ENUM (
|
||||
'app',
|
||||
'cms'
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE IF EXISTS user_scope;
|
||||
|
||||
19
migrations/20200428072232-create-users.sql
Normal file
19
migrations/20200428072232-create-users.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE users (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
username varchar(255),
|
||||
"password" text,
|
||||
is_active bool NOT NULL,
|
||||
-- TODO: use user_scope enum as "scopes user_scope[]" when supported
|
||||
-- https://github.com/volatiletech/sqlboiler/issues/739
|
||||
scopes text[] NOT NULL,
|
||||
last_authenticated_at timestamptz,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT users_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT users_username_key UNIQUE (username)
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
15
migrations/20200428072359-create-app-user-profiles.sql
Normal file
15
migrations/20200428072359-create-app-user-profiles.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE app_user_profiles (
|
||||
user_id uuid NOT NULL,
|
||||
legal_accepted_at timestamptz,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT app_user_profiles_pkey PRIMARY KEY (user_id)
|
||||
);
|
||||
|
||||
ALTER TABLE app_user_profiles
|
||||
ADD CONSTRAINT app_user_profiles_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS app_user_profiles;
|
||||
|
||||
18
migrations/20200428072541-create-access-tokens.sql
Normal file
18
migrations/20200428072541-create-access-tokens.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE access_tokens (
|
||||
token uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
valid_until timestamptz NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT access_tokens_pkey PRIMARY KEY (token)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_access_tokens_fk_user_uid ON access_tokens USING btree (user_id);
|
||||
|
||||
ALTER TABLE access_tokens
|
||||
ADD CONSTRAINT access_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS access_tokens;
|
||||
|
||||
17
migrations/20200428072639-create-refresh-tokens.sql
Normal file
17
migrations/20200428072639-create-refresh-tokens.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE refresh_tokens (
|
||||
token uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
user_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT refresh_tokens_pkey PRIMARY KEY (token)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_refresh_tokens_fk_user_uid ON refresh_tokens USING btree (user_id);
|
||||
|
||||
ALTER TABLE refresh_tokens
|
||||
ADD CONSTRAINT refresh_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS refresh_tokens;
|
||||
|
||||
18
migrations/20200428072651-create-password-reset-tokens.sql
Normal file
18
migrations/20200428072651-create-password-reset-tokens.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE password_reset_tokens (
|
||||
token uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
valid_until timestamptz NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT password_reset_tokens_pkey PRIMARY KEY (token)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_password_reset_tokens_fk_user_uid ON password_reset_tokens USING btree (user_id);
|
||||
|
||||
ALTER TABLE password_reset_tokens
|
||||
ADD CONSTRAINT password_reset_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS password_reset_tokens;
|
||||
|
||||
29
migrations/20200529112509-create-push-token.sql
Normal file
29
migrations/20200529112509-create-push-token.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE provider_type AS ENUM (
|
||||
'fcm',
|
||||
'apn'
|
||||
);
|
||||
|
||||
CREATE TABLE push_tokens (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
token text NOT NULL,
|
||||
provider provider_type NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT push_tokens_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT push_tokens_token_key UNIQUE (token)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_push_tokens_fk_user_id ON push_tokens USING btree (user_id);
|
||||
|
||||
CREATE INDEX idx_push_tokens_token ON push_tokens USING btree (token);
|
||||
|
||||
ALTER TABLE push_tokens
|
||||
ADD CONSTRAINT push_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS push_tokens;
|
||||
|
||||
DROP TYPE IF EXISTS provider_type;
|
||||
|
||||
6
migrations/20200811180414-create-health-sequence.sql
Normal file
6
migrations/20200811180414-create-health-sequence.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- +migrate Up
|
||||
CREATE SEQUENCE seq_health;
|
||||
|
||||
-- +migrate Down
|
||||
DROP SEQUENCE IF EXISTS seq_health;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE confirmation_tokens (
|
||||
token uuid NOT NULL DEFAULT uuid_generate_v4 (),
|
||||
valid_until timestamptz NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
updated_at timestamptz NOT NULL,
|
||||
CONSTRAINT confirmation_tokens_pkey PRIMARY KEY (token)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_confirmation_tokens_fk_user_uid ON confirmation_tokens USING btree (user_id);
|
||||
|
||||
ALTER TABLE confirmation_tokens
|
||||
ADD CONSTRAINT confirmation_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN requires_confirmation boolean NOT NULL DEFAULT FALSE;
|
||||
|
||||
-- +migrate Down
|
||||
ALTER TABLE users
|
||||
DROP COLUMN requires_confirmation;
|
||||
|
||||
DROP TABLE IF EXISTS confirmation_tokens;
|
||||
|
||||
6
migrations/README.md
Normal file
6
migrations/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# `/migrations`
|
||||
|
||||
Our database migrations are plain SQL and managed via `sql-migrate`, see:
|
||||
* https://github.com/rubenv/sql-migrate#usage
|
||||
* https://github.com/rubenv/sql-migrate#writing-migrations
|
||||
|
||||
Reference in New Issue
Block a user