From c93ff4a3aac1fd3b84bfcb34e0c1a4d16fec70c5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 29 Mar 2026 23:00:42 -0400 Subject: [PATCH] migrations wip (do not migrate with these yet!) --- .../down.sql | 5 ++ .../2026-03-29-150019-0000_characters/up.sql | 55 ++++++++++++++ .../down.sql | 5 ++ .../up.sql | 60 ++++++++++++++++ .../down.sql | 5 ++ .../up.sql | 26 +++++++ .../down.sql | 5 ++ .../up.sql | 25 +++++++ .../characters/character_creation_assets.sql | 29 ++++++++ .../characters/character_creation_prompts.sql | 28 ++++++++ .../character_third_party_entities.sql | 71 +++++++++++++++++++ .../characters/characters.sql | 60 ++++++++++++++++ .../generic_inference_jobs.sql | 1 + 13 files changed, 375 insertions(+) create mode 100644 _database/sql/migrations/2026-03-29-150019-0000_characters/down.sql create mode 100644 _database/sql/migrations/2026-03-29-150019-0000_characters/up.sql create mode 100644 _database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/down.sql create mode 100644 _database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/up.sql create mode 100644 _database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/down.sql create mode 100644 _database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/up.sql create mode 100644 _database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/down.sql create mode 100644 _database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/up.sql create mode 100644 _database/sql/migrations_squashed/characters/character_creation_assets.sql create mode 100644 _database/sql/migrations_squashed/characters/character_creation_prompts.sql create mode 100644 _database/sql/migrations_squashed/characters/character_third_party_entities.sql create mode 100644 _database/sql/migrations_squashed/characters/characters.sql diff --git a/_database/sql/migrations/2026-03-29-150019-0000_characters/down.sql b/_database/sql/migrations/2026-03-29-150019-0000_characters/down.sql new file mode 100644 index 0000000000..91f03efa2b --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150019-0000_characters/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE IF EXISTS characters; diff --git a/_database/sql/migrations/2026-03-29-150019-0000_characters/up.sql b/_database/sql/migrations/2026-03-29-150019-0000_characters/up.sql new file mode 100644 index 0000000000..fde055800c --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150019-0000_characters/up.sql @@ -0,0 +1,55 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE TABLE characters ( + -- Not used for anything except replication (private, not even used in queries) + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Public-facing "primary key" (PUBLIC) + token VARCHAR(32) NOT NULL, + + -- Whether the character has been fully created and is available for use. + -- A character may exist in the database before its creation job completes. + is_active BOOLEAN NOT NULL DEFAULT false, + + -- ========== CHARACTER DETAILS ========== + + -- User's display name for the character. + name VARCHAR(255) NOT NULL, + + -- Optional user description of the character. + maybe_description VARCHAR(512) DEFAULT NULL, + + -- ========== MEDIA ========== + + -- Avatar image (cropped to face, ideally). + maybe_avatar_media_token VARCHAR(32) DEFAULT NULL, + + -- Full-size reference image. + maybe_full_image_media_token VARCHAR(32) DEFAULT NULL, + + -- ========== CREATOR ========== + + -- The user who created this character. + maybe_creator_user_token VARCHAR(32) DEFAULT NULL, + + -- For abuse tracking. + creator_ip_address VARCHAR(40) NOT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + UNIQUE KEY (token), + KEY index_maybe_creator_user_token (maybe_creator_user_token), + KEY index_is_active (is_active), + KEY index_created_at (created_at), + KEY index_deleted_at (deleted_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/down.sql b/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/down.sql new file mode 100644 index 0000000000..664bbb5cda --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE IF EXISTS character_third_party_entities; diff --git a/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/up.sql b/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/up.sql new file mode 100644 index 0000000000..1cb3e4c6a3 --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150026-0000_character_third_party_entities/up.sql @@ -0,0 +1,60 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE TABLE character_third_party_entities ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- Whether this third-party entity is active and usable. + is_active BOOLEAN NOT NULL DEFAULT false, + + -- ========== THIRD PARTY DETAILS ========== + + -- Which third-party system the character lives in (enum crate type). + -- e.g. "kinovi", "runway", etc. + third_party VARCHAR(32) NOT NULL, + + -- The identifier in the third-party system. + -- e.g. Kinovi's "char_1774752056469_2wlxoq" + third_party_id VARCHAR(64) NOT NULL, + + -- Which types of models can use this character (enum crate type). + -- e.g. "kinovi_seedance_2_pro", "kinovi_seedance_2_fast", etc. + third_party_scopes VARCHAR(32) NOT NULL, + + -- The name used by the third party. + -- Important for Kinovi since characters are referenced by name in prompts. + third_party_name VARCHAR(255) NOT NULL, + + -- An upstream third party of the third party (if any). + -- e.g. Kinovi's assetId "asset-20260329104101-kk5kl" + maybe_fourth_party_id VARCHAR(64) DEFAULT NULL, + + -- ========== JOB TRACKING ========== + + -- Our job system token (if the character was created via a job). + maybe_origin_job_token VARCHAR(32) DEFAULT NULL, + + -- Third party's job system token (if any). + maybe_origin_third_party_job_id VARCHAR(64) DEFAULT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + UNIQUE KEY unique_third_party_id (third_party, third_party_id), + KEY index_character_token (character_token), + KEY index_third_party (third_party), + KEY index_third_party_id (third_party_id), + KEY index_is_active (is_active) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/down.sql b/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/down.sql new file mode 100644 index 0000000000..57dd167c06 --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE IF EXISTS character_creation_assets; diff --git a/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/up.sql b/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/up.sql new file mode 100644 index 0000000000..c12446f400 --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150034-0000_character_creation_assets/up.sql @@ -0,0 +1,26 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Stores the media files (images) used as input when creating a character. +CREATE TABLE character_creation_assets ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- The media file used as a creation input (e.g. reference image). + asset_media_file_token VARCHAR(32) NOT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + KEY index_character_token (character_token), + KEY index_asset_media_file_token (asset_media_file_token) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/down.sql b/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/down.sql new file mode 100644 index 0000000000..a2defc9a85 --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE IF EXISTS character_creation_prompts; diff --git a/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/up.sql b/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/up.sql new file mode 100644 index 0000000000..397513ee38 --- /dev/null +++ b/_database/sql/migrations/2026-03-29-150042-0000_character_creation_prompts/up.sql @@ -0,0 +1,25 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Stores prompts/descriptions used when creating a character. +CREATE TABLE character_creation_prompts ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- The prompt or description used during character creation. + prompt TEXT DEFAULT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + KEY index_character_token (character_token) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/characters/character_creation_assets.sql b/_database/sql/migrations_squashed/characters/character_creation_assets.sql new file mode 100644 index 0000000000..78233d4b6e --- /dev/null +++ b/_database/sql/migrations_squashed/characters/character_creation_assets.sql @@ -0,0 +1,29 @@ +-- NB: This is a manually squashed view of all the CREATE and ALTER statements, +-- with comments attached to the fields for centralized documentation. + +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Stores the media files (images) used as input when creating a character. +CREATE TABLE character_creation_assets ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- The media file used as a creation input (e.g. reference image). + asset_media_file_token VARCHAR(32) NOT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + KEY index_character_token (character_token), + KEY index_asset_media_file_token (asset_media_file_token) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/characters/character_creation_prompts.sql b/_database/sql/migrations_squashed/characters/character_creation_prompts.sql new file mode 100644 index 0000000000..d5a97ea283 --- /dev/null +++ b/_database/sql/migrations_squashed/characters/character_creation_prompts.sql @@ -0,0 +1,28 @@ +-- NB: This is a manually squashed view of all the CREATE and ALTER statements, +-- with comments attached to the fields for centralized documentation. + +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Stores prompts/descriptions used when creating a character. +CREATE TABLE character_creation_prompts ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- The prompt or description used during character creation. + prompt TEXT DEFAULT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + KEY index_character_token (character_token) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/characters/character_third_party_entities.sql b/_database/sql/migrations_squashed/characters/character_third_party_entities.sql new file mode 100644 index 0000000000..d08c1f24d8 --- /dev/null +++ b/_database/sql/migrations_squashed/characters/character_third_party_entities.sql @@ -0,0 +1,71 @@ +-- NB: This is a manually squashed view of all the CREATE and ALTER statements, +-- with comments attached to the fields for centralized documentation. + +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Maps our characters to their representations in third-party systems. +-- A single character may have entries in multiple third-party systems +-- (e.g. Kinovi for Seedance, Runway for Gen-3, etc.). +-- If a third-party character needs to be recreated, a new row is inserted. +CREATE TABLE character_third_party_entities ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Effective "primary key" (PUBLIC) + -- We may need to recreate the character in a third party, so this gets its own token. + token VARCHAR(32) NOT NULL, + + -- Foreign key to the characters table. + character_token VARCHAR(32) NOT NULL, + + -- Whether this third-party entity is active and usable. + is_active BOOLEAN NOT NULL DEFAULT false, + + -- ========== THIRD PARTY DETAILS ========== + + -- Which third-party system the character lives in (enum crate type). + -- e.g. "kinovi", "runway", etc. + third_party VARCHAR(32) NOT NULL, + + -- Which types of models can use this character (enum crate type). + -- e.g. "seedance_2_pro", "seedance_2_fast", etc. + third_party_scopes VARCHAR(32) NOT NULL, + + -- The identifier in the third-party system. + -- e.g. Kinovi's "char_1774752056469_2wlxoq" + third_party_id VARCHAR(64) NOT NULL, + + -- The name used by the third party. + -- Important for Kinovi since characters are referenced by name in prompts. + third_party_name VARCHAR(255) NOT NULL, + + -- An upstream third party of the third party (if any). + -- e.g. Kinovi's assetId "asset-20260329104101-kk5kl" + maybe_fourth_party_id VARCHAR(64) DEFAULT NULL, + + -- ========== JOB TRACKING ========== + + -- Our job system token (if the character was created via a job). + maybe_origin_job_token VARCHAR(32) DEFAULT NULL, + + -- Third party's job system token (if any). + maybe_origin_third_party_job_id VARCHAR(64) DEFAULT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + UNIQUE KEY (token), + KEY index_character_token (character_token), + KEY index_third_party (third_party), + KEY index_third_party_id (third_party_id), + KEY index_is_active (is_active) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/characters/characters.sql b/_database/sql/migrations_squashed/characters/characters.sql new file mode 100644 index 0000000000..b78132d2fc --- /dev/null +++ b/_database/sql/migrations_squashed/characters/characters.sql @@ -0,0 +1,60 @@ +-- NB: This is a manually squashed view of all the CREATE and ALTER statements, +-- with comments attached to the fields for centralized documentation. + +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- Characters are reusable entities that can be referenced in video/image generations. +-- A character is created from one or more reference images and registered with third-party +-- systems (e.g. Kinovi/Seedance) that support character-based generation. +CREATE TABLE characters ( + -- Not used for anything except replication. + id BIGINT(20) NOT NULL AUTO_INCREMENT, + + -- Effective "primary key" (PUBLIC) + token VARCHAR(32) NOT NULL, + + -- Whether the character has been fully created and is available for use. + -- A character may exist in the database before its creation job completes. + is_active BOOLEAN NOT NULL DEFAULT false, + + -- ========== CHARACTER DETAILS ========== + + -- Display name for the character. + name VARCHAR(255) NOT NULL, + + -- Optional description of the character. + maybe_description VARCHAR(512) DEFAULT NULL, + + -- ========== MEDIA ========== + + -- Avatar image (small/thumbnail). + maybe_avatar_media_token VARCHAR(32) DEFAULT NULL, + + -- Full-size reference image. + maybe_full_image_media_token VARCHAR(32) DEFAULT NULL, + + -- ========== CREATOR ========== + + -- The user who created this character. + maybe_creator_user_token VARCHAR(32) DEFAULT NULL, + + -- For abuse tracking. + creator_ip_address VARCHAR(40) NOT NULL, + + -- ========== TIMESTAMPS ========== + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + + -- ========== INDICES ========== + + PRIMARY KEY (id), + UNIQUE KEY (token), + KEY index_maybe_creator_user_token (maybe_creator_user_token), + KEY index_is_active (is_active), + KEY index_created_at (created_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/generic_inference_jobs.sql b/_database/sql/migrations_squashed/generic_inference_jobs.sql index abec304ef1..de83a46240 100644 --- a/_database/sql/migrations_squashed/generic_inference_jobs.sql +++ b/_database/sql/migrations_squashed/generic_inference_jobs.sql @@ -46,6 +46,7 @@ CREATE TABLE generic_inference_jobs ( -- * background_removal inference_category VARCHAR(32) NOT NULL, + -- Enum: InferenceJobExternalThirdParty -- If the job is externally enqueued, this is the third-party service -- responsible for the job. Typically, we won't run an inference job for -- jobs being run on a third party.