|
| 1 | +SET search_path TO bc; |
| 2 | + |
| 3 | +-- region Setup |
| 4 | +CREATE TABLE bc_version |
| 5 | +( |
| 6 | + one_row bool DEFAULT TRUE, |
| 7 | + version text NOT NULL, |
| 8 | + |
| 9 | + PRIMARY KEY (one_row), |
| 10 | + CHECK (one_row) |
| 11 | +); |
| 12 | + |
| 13 | +INSERT INTO bc_version |
| 14 | +VALUES (TRUE, '3.0.0'); |
| 15 | +-- endregion |
| 16 | + |
| 17 | +-- region Components |
| 18 | +CREATE TABLE bc_component |
| 19 | +( |
| 20 | + component_id serial NOT NULL, |
| 21 | + component_type smallint NOT NULL, -- Can also be a group ! (0) |
| 22 | + lifetime_type smallint NOT NULL, |
| 23 | + one_use bool NOT NULL, |
| 24 | + rate_limit_group text NULL, |
| 25 | + filters text array NOT NULL, |
| 26 | + expires_at timestamp with time zone NULL, |
| 27 | + reset_timeout_on_use_duration_ms int NULL, |
| 28 | + rate_limit_discriminator text NULL, |
| 29 | + |
| 30 | + PRIMARY KEY (component_id), |
| 31 | + |
| 32 | + CHECK (component_type BETWEEN 0 AND 2), |
| 33 | + CHECK (lifetime_type BETWEEN 0 AND 1) |
| 34 | +); |
| 35 | + |
| 36 | +CREATE TABLE bc_component_constraints |
| 37 | +( |
| 38 | + component_id int NOT NULL, |
| 39 | + users bigint array NOT NULL, |
| 40 | + roles bigint array NOT NULL, |
| 41 | + permissions bigint NOT NULL, |
| 42 | + |
| 43 | + PRIMARY KEY (component_id), |
| 44 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE |
| 45 | +); |
| 46 | + |
| 47 | +-- Component types |
| 48 | + |
| 49 | +CREATE TABLE bc_ephemeral_handler |
| 50 | +( |
| 51 | + component_id int NOT NULL, |
| 52 | + handler_id int NOT NULL, |
| 53 | + |
| 54 | + PRIMARY KEY (component_id), |
| 55 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE |
| 56 | +); |
| 57 | + |
| 58 | +CREATE TABLE bc_persistent_handler |
| 59 | +( |
| 60 | + component_id int NOT NULL, |
| 61 | + handler_name text NOT NULL, |
| 62 | + user_data bytea array NOT NULL, |
| 63 | + |
| 64 | + PRIMARY KEY (component_id), |
| 65 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE |
| 66 | +); |
| 67 | + |
| 68 | +-- Component timeouts |
| 69 | + |
| 70 | +CREATE TABLE bc_ephemeral_timeout |
| 71 | +( |
| 72 | + component_id int NOT NULL, |
| 73 | + handler_id int NOT NULL, |
| 74 | + |
| 75 | + PRIMARY KEY (component_id), |
| 76 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE |
| 77 | +); |
| 78 | + |
| 79 | +CREATE TABLE bc_persistent_timeout |
| 80 | +( |
| 81 | + component_id int NOT NULL, |
| 82 | + handler_name text NOT NULL, |
| 83 | + user_data bytea array NOT NULL, |
| 84 | + |
| 85 | + PRIMARY KEY (component_id), |
| 86 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE |
| 87 | +); |
| 88 | + |
| 89 | +-- Group, bc_component can already be a group |
| 90 | +-- Associative table |
| 91 | +CREATE TABLE bc_component_component_group |
| 92 | +( |
| 93 | + group_id int NOT NULL, |
| 94 | + component_id int NOT NULL, |
| 95 | + |
| 96 | + FOREIGN KEY (group_id) REFERENCES bc_component ON DELETE CASCADE, |
| 97 | + FOREIGN KEY (component_id) REFERENCES bc_component ON DELETE CASCADE, |
| 98 | + PRIMARY KEY (group_id, component_id) |
| 99 | +); |
| 100 | +-- endregion |
| 101 | + |
| 102 | +-- region Application commands cache |
| 103 | +CREATE TABLE application_commands_cache |
| 104 | +( |
| 105 | + application_id bigint NOT NULL, |
| 106 | + guild_id bigint NULL, |
| 107 | + data text NOT NULL, |
| 108 | + metadata text NOT NULL, |
| 109 | + |
| 110 | + UNIQUE NULLS NOT DISTINCT (application_id, guild_id) |
| 111 | +); |
| 112 | +-- endregion |
0 commit comments