This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accounts, users, groups tables in database
As well as tables binding these together. See #16.
- Loading branch information
1 parent
9e65f5d
commit e10eccb
Showing
7 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
drop table accounts; |
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,7 @@ | ||
-- accounts have names and will be used primarily for billing. | ||
create table accounts ( | ||
id uuid primary key default gen_random_uuid(), | ||
name string not null, | ||
created_at timestamp not null default current_timestamp(), | ||
updated_at timestamp not null default current_timestamp() | ||
); |
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,2 @@ | ||
drop table account_membership; | ||
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,21 @@ | ||
-- users has user information and preferences. | ||
create table users ( | ||
id uuid primary key default gen_random_uuid(), | ||
name string not null, | ||
email string unique not null, | ||
password string not null, | ||
language string not null default 'en-us', | ||
timezone string not null default 'CET', | ||
preferences jsonb not null default '{}', | ||
created_at timestamp not null default current_timestamp(), | ||
updated_at timestamp not null default current_timestamp() | ||
); | ||
|
||
-- account_membership defines who is part of an account. | ||
-- Note that it's a many-to-many relationship, so one user can be a part of multiple accounts, | ||
-- and an account can (obviously) have many users. | ||
create table account_membership ( | ||
account_id uuid references accounts(id) on delete cascade, | ||
user_id uuid references users(id) on delete cascade, | ||
primary key (account_id, user_id) | ||
); |
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,3 @@ | ||
drop table group_membership; | ||
drop table group_ownership; | ||
drop table groups; |
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,23 @@ | ||
-- groups of users are named and have a secret that's used to join the group. | ||
create table groups ( | ||
id uuid primary key default gen_random_uuid(), | ||
name string not null, | ||
invitation_secret bytes not null default uuid_v4(), | ||
created_at timestamp not null default current_timestamp(), | ||
updated_at timestamp not null default current_timestamp() | ||
); | ||
|
||
-- group_membership defines who's part of a group. | ||
create table group_membership ( | ||
group_id uuid references groups(id) on delete cascade, | ||
user_id uuid references users(id) on delete cascade, | ||
primary key (group_id, user_id) | ||
); | ||
|
||
-- group_ownership defines who owns a group. | ||
-- Note that a user cannot be deleted if the user is a group owner. | ||
create table group_ownership ( | ||
group_id uuid references groups(id) on delete cascade, | ||
user_id uuid references users(id), | ||
primary key (group_id, user_id) | ||
); |