-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playground): playground back-end (#222)
This allows for sharing, loading and flagging playgrounds on MDN. We use gists as the storage back-end but track them in our db to mitigate and add features in the future.
- Loading branch information
Showing
21 changed files
with
722 additions
and
4 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
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
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 TRIGGER set_deleted_user_id ON playground; | ||
DROP FUNCTION set_deleted_user_id; | ||
DROP TABLE playground; |
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,25 @@ | ||
CREATE TABLE playground ( | ||
id BIGSERIAL PRIMARY KEY, | ||
user_id BIGINT NULL REFERENCES users (id) ON DELETE SET NULL, | ||
gist TEXT NOT NULL UNIQUE, | ||
active BOOLEAN NOT NULL DEFAULT TRUE, | ||
flagged BOOLEAN NOT NULL DEFAULT FALSE, | ||
deleted_user_id BIGINT DEFAULT NULL | ||
); | ||
|
||
CREATE INDEX playground_gist ON playground (gist); | ||
|
||
CREATE FUNCTION set_deleted_user_id() RETURNS trigger AS $$ | ||
BEGIN | ||
IF OLD.user_id IS NOT NULL AND NEW.user_id IS NULL THEN | ||
NEW.deleted_user_id := OLD.user_id; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER set_deleted_user_id | ||
BEFORE UPDATE ON playground | ||
FOR EACH ROW | ||
WHEN (OLD.user_id IS NOT NULL AND NEW.user_id IS NULL) | ||
EXECUTE FUNCTION set_deleted_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
Oops, something went wrong.