From e7929b20998db95f2ac21e136d191d22de60b21c Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Tue, 13 Nov 2018 04:34:26 -0300 Subject: [PATCH] schema.sql: fix table ordering --- schema.sql | 58 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/schema.sql b/schema.sql index 2d3d5c6..7f66a7b 100644 --- a/schema.sql +++ b/schema.sql @@ -331,34 +331,6 @@ CREATE TABLE IF NOT EXISTS group_dm_members ( ); -CREATE TABLE IF NOT EXISTS channel_overwrites ( - channel_id bigint REFERENCES channels (id) ON DELETE CASCADE, - - -- target_type = 0 -> use target_user - -- target_type = 1 -> use target_role - -- discord already has overwrite.type = 'role' | 'member' - -- so this allows us to be more compliant with the API - target_type integer default null, - - -- keeping both columns separated and as foreign keys - -- instead of a single "target_id bigint" column - -- makes us able to remove the channel overwrites of - -- a role when its deleted (same for users, etc). - target_role bigint REFERENCES roles (id) ON DELETE CASCADE, - target_user bigint REFERENCES users (id) ON DELETE CASCADE, - - -- since those are permission bit sets - -- they're bigints (64bits), discord, - -- for now, only needs 53. - allow bigint DEFAULT 0, - deny bigint DEFAULT 0 -); - --- columns in private keys can't have NULL values, --- so instead we use a custom constraint with UNIQUE - -ALTER TABLE channel_overwrites ADD CONSTRAINT channel_overwrites_uniq - UNIQUE (channel_id, target_role, target_user); CREATE TABLE IF NOT EXISTS features ( @@ -461,6 +433,36 @@ CREATE TABLE IF NOT EXISTS roles ( ); +CREATE TABLE IF NOT EXISTS channel_overwrites ( + channel_id bigint REFERENCES channels (id) ON DELETE CASCADE, + + -- target_type = 0 -> use target_user + -- target_type = 1 -> use target_role + -- discord already has overwrite.type = 'role' | 'member' + -- so this allows us to be more compliant with the API + target_type integer default null, + + -- keeping both columns separated and as foreign keys + -- instead of a single "target_id bigint" column + -- makes us able to remove the channel overwrites of + -- a role when its deleted (same for users, etc). + target_role bigint REFERENCES roles (id) ON DELETE CASCADE, + target_user bigint REFERENCES users (id) ON DELETE CASCADE, + + -- since those are permission bit sets + -- they're bigints (64bits), discord, + -- for now, only needs 53. + allow bigint DEFAULT 0, + deny bigint DEFAULT 0 +); + +-- columns in private keys can't have NULL values, +-- so instead we use a custom constraint with UNIQUE + +ALTER TABLE channel_overwrites ADD CONSTRAINT channel_overwrites_uniq + UNIQUE (channel_id, target_role, target_user); + + CREATE TABLE IF NOT EXISTS guild_whitelists ( emoji_id bigint REFERENCES guild_emoji (id) ON DELETE CASCADE, role_id bigint REFERENCES roles (id),