diff --git a/_sql/migrations/2024-05-13-035106_beta_keys/down.sql b/_sql/migrations/2024-05-13-035106_beta_keys/down.sql index 291a97c5ce..9a8a2526e5 100644 --- a/_sql/migrations/2024-05-13-035106_beta_keys/down.sql +++ b/_sql/migrations/2024-05-13-035106_beta_keys/down.sql @@ -1 +1,5 @@ --- This file should undo anything in `up.sql` \ No newline at end of file +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE beta_keys; diff --git a/_sql/migrations/2024-05-13-035106_beta_keys/up.sql b/_sql/migrations/2024-05-13-035106_beta_keys/up.sql index 33cf74b578..bf37e6084b 100644 --- a/_sql/migrations/2024-05-13-035106_beta_keys/up.sql +++ b/_sql/migrations/2024-05-13-035106_beta_keys/up.sql @@ -1 +1,52 @@ --- Your SQL goes here \ No newline at end of file +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE TABLE beta_keys ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- ========== PRIMARY, FOREIGN KEYS, and POLYMORPHISM ========== + + -- Effective "primary key" of the beta key. + token VARCHAR(32) NOT NULL, + + -- ========== KEY INFO ========== + + -- Name of the product the key applies to + product_name VARCHAR(32) NOT NULL, + + -- The actual key value that the user inputs. + -- Crockford-encoded. + key_value VARCHAR(32) DEFAULT NULL, + + -- ========== USERS ========== + + -- The user that redeems the beta key. + -- If set, the key has been redeemed. + maybe_redeemer_user_token VARCHAR(32) DEFAULT NULL, + + -- The user that redeems the beta key. + -- Based on a cookie sent by the frontend. + maybe_redeemer_anonymous_visitor_token VARCHAR(32) DEFAULT NULL, + + -- The user that redeems the beta key. + -- Wide enough for IPv4/6 + maybe_redeemer_ip_address VARCHAR(40) DEFAULT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + maybe_redeemed_at TIMESTAMP NULL, + + -- INDICES -- + PRIMARY KEY (id), + UNIQUE KEY (entity_type, entity_token), + + KEY index_maybe_sort_order_asc (maybe_sort_order ASC), + KEY index_maybe_sort_order_desc (maybe_sort_order DESC), + + KEY index_created_at (created_at), + KEY index_deleted_at (deleted_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;