From 23e6f552e78bfd99607dcb0fd2da04369574e044 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 16 Feb 2022 02:41:02 -0500 Subject: [PATCH] migrations for api tokens --- .../2022-02-16-072149_api_tokens/down.sql | 5 ++++ .../2022-02-16-072149_api_tokens/up.sql | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 _migrations/2022-02-16-072149_api_tokens/down.sql create mode 100644 _migrations/2022-02-16-072149_api_tokens/up.sql diff --git a/_migrations/2022-02-16-072149_api_tokens/down.sql b/_migrations/2022-02-16-072149_api_tokens/down.sql new file mode 100644 index 0000000000..f8dce0d9c1 --- /dev/null +++ b/_migrations/2022-02-16-072149_api_tokens/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE api_tokens; diff --git a/_migrations/2022-02-16-072149_api_tokens/up.sql b/_migrations/2022-02-16-072149_api_tokens/up.sql new file mode 100644 index 0000000000..df5aaeb247 --- /dev/null +++ b/_migrations/2022-02-16-072149_api_tokens/up.sql @@ -0,0 +1,30 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- We'll use application logic to kill any API keys beyond the most recent 5 "active" a user creates. +CREATE TABLE api_tokens ( + -- Not used for anything except replication. + id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, + + -- This is the secret API token value + api_token VARCHAR(32) NOT NULL, + + -- Foreign key to user that owns the API token. + -- A user can have several. + user_token VARCHAR(32) NOT NULL, + + -- A user-defined short description (optional) + maybe_short_description VARCHAR(32) DEFAULT NULL, + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP, + + -- INDICES -- + PRIMARY KEY (id), + UNIQUE KEY (api_token), + KEY fk_user_token (user_token), + KEY index_deleted_at (deleted_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;