-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
snapshot: database migrations, registration actions and views
- Loading branch information
Showing
23 changed files
with
1,986 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
*.ez | ||
/build | ||
erl_crash.dump | ||
/node_modules | ||
/priv/static/css/main.css | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
db/migrations/20240711215416_pending_user_tenant_roles.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.