Last active
August 9, 2023 03:48
-
-
Save trvswgnr/ab4f8705d51038c9f73e9cd8d8154bb7 to your computer and use it in GitHub Desktop.
daxxer sql challenge
This file contains hidden or 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
CREATE TABLE workspaces ( | |
id SERIAL PRIMARY KEY, | |
name VARCHAR(255) NOT NULL | |
); | |
CREATE TABLE users ( | |
id SERIAL, | |
workspace_id INT NOT NULL, | |
email VARCHAR(255) NOT NULL, | |
PRIMARY KEY (workspace_id, id), | |
FOREIGN KEY (workspace_id) REFERENCES workspaces(id), | |
UNIQUE (workspace_id, email) | |
); | |
CREATE INDEX idx_users_email ON users(email); | |
CREATE TABLE orders ( | |
id SERIAL, | |
workspace_id INT NOT NULL, | |
user_id INT NOT NULL, | |
data JSONB NOT NULL, | |
PRIMARY KEY (workspace_id, id), | |
FOREIGN KEY (workspace_id, user_id) REFERENCES users(workspace_id, id), | |
UNIQUE (workspace_id, user_id, id) | |
); | |
CREATE INDEX idx_orders_user ON orders(workspace_id, user_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment