Skip to content

Commit

Permalink
Rename invited_by to sponsor and add code column
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <[email protected]>
  • Loading branch information
rdimitrov committed Jun 5, 2024
1 parent 4ac5d28 commit bb19dd9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion database/migrations/000061_user_invites.down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN;
DROP INDEX IF EXISTS idx_user_invites_email;
DROP INDEX IF EXISTS idx_user_invites_project;
DROP INDEX IF EXISTS idx_user_invites_invitee;
DROP INDEX IF EXISTS idx_user_invites_invited_by;
DROP INDEX IF EXISTS idx_user_invites_sponsor;

-- drop the table
DROP TABLE IF EXISTS user_invites;
Expand Down
9 changes: 6 additions & 3 deletions database/migrations/000061_user_invites.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ CREATE TABLE IF NOT EXISTS user_invites(
role user_role NOT NULL DEFAULT 'viewer',
project UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
invitee INTEGER NULL REFERENCES users(id) ON DELETE CASCADE,
invited_by INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
sponsor INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
code TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
-- ensure there's one invite for this email per project
UNIQUE (email, project)
UNIQUE (email, project),
-- ensure code/nonce is unique
UNIQUE (code)
);

-- create an index on the email column
Expand All @@ -43,6 +46,6 @@ CREATE INDEX idx_user_invites_project ON user_invites(project);
CREATE INDEX idx_user_invites_invitee ON user_invites(invitee);

-- create an index on the invited_by column
CREATE INDEX idx_user_invites_invited_by ON user_invites(invited_by);
CREATE INDEX idx_user_invites_sponsor ON user_invites(sponsor);

COMMIT;
3 changes: 2 additions & 1 deletion internal/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb19dd9

Please sign in to comment.