Skip to content

Instantly share code, notes, and snippets.

@mgwedd
Last active April 28, 2023 00:06
Show Gist options
  • Save mgwedd/ad8ba5e74ce617533d5d2238c777c4f5 to your computer and use it in GitHub Desktop.
Save mgwedd/ad8ba5e74ce617533d5d2238c777c4f5 to your computer and use it in GitHub Desktop.
CREATE TABLE Users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255)
);
CREATE TABLE Booklets (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL
);
CREATE TABLE Clips (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL
);
CREATE TYPE RoleType AS ENUM ('EDITOR', 'COMMENTER', 'VIEWER', 'OWNER');
CREATE TABLE UserBookletRoles (
id SERIAL PRIMARY KEY,
role RoleType NOT NULL,
userId INT NOT NULL,
bookletId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES Users(id),
FOREIGN KEY (bookletId) REFERENCES Booklets(id),
UNIQUE (userId, bookletId)
);
CREATE TABLE UserClipRoles (
id SERIAL PRIMARY KEY,
role RoleType NOT NULL,
userId INT NOT NULL,
clipId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES Users(id),
FOREIGN KEY (clipId) REFERENCES Clips(id),
UNIQUE (userId, clipId)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment