Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Aug 26, 2024
1 parent 234a77d commit 725885d
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CREATE TABLE code_giveaways (
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMP WITH TIME ZONE,
course_id UUID NOT NULL REFERENCES courses(id),
course_module_id UUID REFERENCES course_modules(id),
enabled BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TRIGGER set_timestamp BEFORE
UPDATE ON code_giveaways FOR EACH ROW EXECUTE PROCEDURE trigger_set_timestamp();
Expand All @@ -13,6 +15,8 @@ COMMENT ON COLUMN code_giveaways.created_at IS 'Timestamp when the record was cr
COMMENT ON COLUMN code_giveaways.updated_at IS 'Timestamp when the record was last updated. The field is updated automatically by the set_timestamp trigger.';
COMMENT ON COLUMN code_giveaways.deleted_at IS 'Timestamp when the record was deleted. If null, the record is not deleted.';
COMMENT ON COLUMN code_giveaways.course_id IS 'The course the code giveaway is available on.';
COMMENT ON COLUMN code_giveaways.course_module_id IS 'The course module the code giveaway is available on. If null, the giveaway has not been placed on a course module on the CMS.';
COMMENT ON COLUMN code_giveaways.enabled IS 'If the giveaway is enabled, the codes can be given to students.';

CREATE TABLE code_giveaway_codes (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
Expand All @@ -22,14 +26,22 @@ CREATE TABLE code_giveaway_codes (
code_giveaway_id UUID NOT NULL REFERENCES code_giveaways(id),
code_given_to_user_id UUID REFERENCES users(id),
added_by_user_id UUID NOT NULL REFERENCES users(id),
code VARCHAR(2048) NOT NULL,
-- A user can only receive one code from a giveaway.
UNIQUE NULLS NOT DISTINCT (
code_giveaway_id,
code_given_to_user_id,
deleted_at
)
);
CREATE TRIGGER set_timestamp BEFORE
UPDATE ON code_giveaway_codes FOR EACH ROW EXECUTE PROCEDURE trigger_set_timestamp();
COMMENT ON TABLE code_giveaway_codes IS 'A code that is available in a code giveaway.';
COMMENT ON TABLE code_giveaway_codes IS 'A code that is available in a code giveaway. A user can only receive one code from a giveaway.';
COMMENT ON COLUMN code_giveaway_codes.id IS 'A unique, stable identifier for the record.';
COMMENT ON COLUMN code_giveaway_codes.created_at IS 'Timestamp when the record was created.';
COMMENT ON COLUMN code_giveaway_codes.updated_at IS 'Timestamp when the record was last updated. The field is updated automatically by the set_timestamp trigger.';
COMMENT ON COLUMN code_giveaway_codes.deleted_at IS 'Timestamp when the record was deleted. If null, the record is not deleted.';
COMMENT ON COLUMN code_giveaway_codes.code_giveaway_id IS 'The code giveaway the code is available in.';
COMMENT ON COLUMN code_giveaway_codes.code_given_to_user_id IS 'The user the code was given to. If null, the code has not been given to a user.';
COMMENT ON COLUMN code_giveaway_codes.added_by_user_id IS 'The user that added the code to the giveaway.';
COMMENT ON COLUMN code_giveaway_codes.code IS 'The code that is given to a user.';

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

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

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

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

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

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

Loading

0 comments on commit 725885d

Please sign in to comment.