Skip to content

Commit

Permalink
snapshot: database migrations, registration actions and views
Browse files Browse the repository at this point in the history
  • Loading branch information
skinkade committed Jul 11, 2024
1 parent fad6911 commit 4079a0e
Show file tree
Hide file tree
Showing 23 changed files with 1,986 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.ez
/build
erl_crash.dump
/node_modules
/priv/static/css/main.css
.env
17 changes: 17 additions & 0 deletions db/migrations/20240711213952_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- migrate:up

CREATE EXTENSION IF NOT EXISTS citext;

CREATE TABLE users (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email_address citext NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE UNIQUE INDEX UX_user_email
ON users (email_address);

-- migrate:down

DROP TABLE users;
11 changes: 11 additions & 0 deletions db/migrations/20240711214259_tenants.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- migrate:up

CREATE TABLE tenants (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
full_name TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
)

-- migrate:down

DROP TABLE tenants;
14 changes: 14 additions & 0 deletions db/migrations/20240711214448_user_tenant_roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- migrate:up

CREATE TABLE user_tenant_roles(
user_id INT NOT NULL
REFERENCES users (id),
tenant_id INT NOT NULL
REFERENCES tenants (id),
PRIMARY KEY (user_id, tenant_id),
role_desc TEXT NOT NULL
)

-- migrate:down

DROP TABLE user_tenant_roles;
17 changes: 17 additions & 0 deletions db/migrations/20240711214849_user_sessions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- migrate:up

CREATE TABLE user_sessions (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
session_hash BYTEA NOT NULL,
user_id INT NOT NULL
REFERENCES users (id),
created_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL
);

CREATE UNIQUE INDEX UX_session_hash
ON user_sessions (session_hash);

-- migrate:down

DROP TABLE user_sessions;
19 changes: 19 additions & 0 deletions db/migrations/20240711215158_pending_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- migrate:up

CREATE TABLE pending_users (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email_address citext NOT NULL,
invite_token_hash BYTEA NOT NULL,
invited_at TIMESTAMPTZ NOT NULL DEFAULT now(),
expires_at TIMESTAMPTZ NOT NULL
);

CREATE UNIQUE INDEX UX_pending_user_token_hash
ON pending_users (invite_token_hash);

CREATE UNIQUE INDEX UX_pending_user_email
ON pending_users (email_address);

-- migrate:down

DROP TABLE pending_users;
13 changes: 13 additions & 0 deletions db/migrations/20240711215416_pending_user_tenant_roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- migrate:up

CREATE TABLE pending_user_tenant_roles (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email_address citext NOT NULL,
tenant_id INT NOT NULL
REFERENCES tenants (id),
role_desc TEXT NOT NULL
);

-- migrate:down

DROP TABLE pending_user_tenant_roles;
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
db:
image: postgres:16-alpine
container_name: wisp_multitenant_demo_db
restart: always
environment:
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: wisp_multitenant_demo
volumes:
- pgdata:/var/lib/postgresql/wisp_multitenant_demo_data
ports:
- "127.0.0.1:5432:5432"

volumes:
pgdata:
2 changes: 2 additions & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ antigone = ">= 1.1.0 and < 2.0.0"
gleam_crypto = ">= 1.3.0 and < 2.0.0"
mist = ">= 1.2.0 and < 2.0.0"
gleam_erlang = ">= 0.25.0 and < 1.0.0"
formal = ">= 2.0.0 and < 3.0.0"
lustre = ">= 4.3.0 and < 5.0.0"

[dev-dependencies]
gleeunit = ">= 1.0.0 and < 2.0.0"
8 changes: 6 additions & 2 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ packages = [
{ name = "elixir_make", version = "0.8.4", build_tools = ["mix"], requirements = ["castore", "certifi"], otp_app = "elixir_make", source = "hex", outer_checksum = "6E7F1D619B5F61DFABD0A20AA268E575572B542AC31723293A4C1A567D5EF040" },
{ name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" },
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
{ name = "formal", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "formal", source = "hex", outer_checksum = "BD0934C9E3D2CB77FAB0138045B6C2D7DC11951D19BC8A7FF44125ADF90FAD1B" },
{ name = "gleam_crypto", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "ADD058DEDE8F0341F1ADE3AAC492A224F15700829D9A3A3F9ADF370F875C51B7" },
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
{ name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" },
Expand All @@ -24,6 +25,7 @@ packages = [
{ name = "gramps", version = "2.0.3", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "3CCAA6E081225180D95C79679D383BBF51C8D1FDC1B84DA1DA444F628C373793" },
{ name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" },
{ name = "logging", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "FCB111401BDB4703A440A94FF8CC7DA521112269C065F219C2766998333E7738" },
{ name = "lustre", version = "4.3.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "43642C0602D3E2D6FEC3E24173D68A1F8E646969B53A2B0A5EB61238DDA739C4" },
{ name = "marceau", version = "1.2.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "5188D643C181EE350D8A20A3BDBD63AF7B6C505DE333CFBE05EF642ADD88A59B" },
{ name = "mist", version = "1.2.0", build_tools = ["gleam"], requirements = ["birl", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "109B4D64E68C104CC23BB3CC5441ECD479DD7444889DA01113B75C6AF0F0E17B" },
{ name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" },
Expand All @@ -39,10 +41,12 @@ packages = [
[requirements]
antigone = { version = ">= 1.1.0 and < 2.0.0" }
birl = { version = ">= 1.7.1 and < 2.0.0" }
formal = { version = ">= 2.0.0 and < 3.0.0" }
gleam_crypto = { version = ">= 1.3.0 and < 2.0.0" }
gleam_erlang = { version = ">= 0.25.0 and < 1.0.0"}
gleam_erlang = { version = ">= 0.25.0 and < 1.0.0" }
gleam_pgo = { version = ">= 0.12.0 and < 1.0.0" }
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
mist = { version = ">= 1.2.0 and < 2.0.0"}
lustre = { version = ">= 4.3.0 and < 5.0.0"}
mist = { version = ">= 1.2.0 and < 2.0.0" }
wisp = { version = ">= 0.15.0 and < 1.0.0" }
Loading

0 comments on commit 4079a0e

Please sign in to comment.