From a81428913d2332e6c8fe075e416ed2f38fe1973c Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 8 Apr 2023 19:54:58 -0700 Subject: [PATCH] migrate generic_inference_jobs to include better indices/foreign keys --- .../down.sql | 7 ++++++ .../up.sql | 7 ++++++ .../down.sql | 5 ++++ .../up.sql | 5 ++++ .../down.sql | 8 ++++++ .../up.sql | 10 ++++++++ .../generic_inference_jobs.sql | 25 +++++++++++-------- 7 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 _sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/down.sql create mode 100644 _sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/up.sql create mode 100644 _sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/down.sql create mode 100644 _sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/up.sql create mode 100644 _sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/down.sql create mode 100644 _sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/up.sql diff --git a/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/down.sql b/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/down.sql new file mode 100644 index 0000000000..720c4299e9 --- /dev/null +++ b/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/down.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs RENAME COLUMN inference_category TO inference_type; + +ALTER TABLE generic_inference_jobs RENAME INDEX index_inference_category TO index_inference_type; diff --git a/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/up.sql b/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/up.sql new file mode 100644 index 0000000000..ea2118025c --- /dev/null +++ b/_sql/migrations/2023-04-09-020030_alter_inference_jobs_rename_inference_type/up.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs RENAME COLUMN inference_type TO inference_category; + +ALTER TABLE generic_inference_jobs RENAME INDEX index_inference_type TO index_inference_category; diff --git a/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/down.sql b/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/down.sql new file mode 100644 index 0000000000..ed66e7d270 --- /dev/null +++ b/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs MODIFY maybe_model_token VARCHAR(32) DEFAULT NULL AFTER maybe_raw_inference_text; diff --git a/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/up.sql b/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/up.sql new file mode 100644 index 0000000000..1aa7f0f68f --- /dev/null +++ b/_sql/migrations/2023-04-09-020102_alter_inference_jobs_reorder_model_token/up.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs MODIFY maybe_model_token VARCHAR(32) DEFAULT NULL AFTER inference_category; diff --git a/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/down.sql b/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/down.sql new file mode 100644 index 0000000000..490bb15004 --- /dev/null +++ b/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/down.sql @@ -0,0 +1,8 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP INDEX index_maybe_model_type_and_maybe_model_token ON generic_inference_jobs; +DROP INDEX index_maybe_model_type ON generic_inference_jobs; + +ALTER TABLE generic_inference_jobs DROP COLUMN maybe_model_type; diff --git a/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/up.sql b/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/up.sql new file mode 100644 index 0000000000..9f6d6d1746 --- /dev/null +++ b/_sql/migrations/2023-04-09-022655_alter_inference_jobs_add_model_type/up.sql @@ -0,0 +1,10 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs + ADD COLUMN maybe_model_type VARCHAR(32) DEFAULT NULL + AFTER inference_category; + +CREATE INDEX index_maybe_model_type_and_maybe_model_token ON generic_inference_jobs (maybe_model_type, maybe_model_token); +CREATE INDEX index_maybe_model_type ON generic_inference_jobs (maybe_model_type); diff --git a/_sql/migrations_squashed/generic_inference_jobs.sql b/_sql/migrations_squashed/generic_inference_jobs.sql index 57bd9a0625..027e3d7f44 100644 --- a/_sql/migrations_squashed/generic_inference_jobs.sql +++ b/_sql/migrations_squashed/generic_inference_jobs.sql @@ -17,15 +17,21 @@ CREATE TABLE generic_inference_jobs ( -- ========== INFERENCE DETAILS ========== - -- TODO: Rename this inference_category and add `maybe_model_type` - -- Type of inference + -- Broad category of inference -- Examples (may not be up to date): -- * text_to_speech -- * voice_conversion - inference_type VARCHAR(32) NOT NULL, + inference_category VARCHAR(32) NOT NULL, - -- TODO: Add `maybe_model_type` here - -- TODO: Move maybe_model_token here + -- Potential part of the composite foreign key to the primary model being used, if any. + -- This will normally live in `maybe_inference_args`, but in this case, it's useful for + -- running easy database analytical queries. + maybe_model_type VARCHAR(32) DEFAULT NULL, + + -- Potential part of the composite foreign key to the primary model being used, if any. + -- This will normally live in `maybe_inference_args`, but in this case, it's useful for + -- running easy database analytical queries. + maybe_model_token VARCHAR(32) DEFAULT NULL, -- Polymorphic arguments payload that depends on the type of inference job. -- TEXT = 65,535 bytes (64 KiB), ~= 4 bytes per UTF-8 character, ~ 16383 characters. @@ -35,11 +41,6 @@ CREATE TABLE generic_inference_jobs ( -- TEXT = 65,535 bytes (64 KiB), ~= 4 bytes per UTF-8 character, ~ 16383 characters. maybe_raw_inference_text TEXT DEFAULT NULL, - -- Potential foreign key to the primary model being used, if any. - -- This will normally live in `maybe_inference_args`, but in this case, it's useful for - -- running easy database analytical queries. - maybe_model_token VARCHAR(32) DEFAULT NULL, - -- ========== SUCCESS CASE ========== -- The type of the object will vary based on the type of the upload, @@ -153,7 +154,9 @@ CREATE TABLE generic_inference_jobs ( PRIMARY KEY (id), UNIQUE KEY (token), UNIQUE KEY (uuid_idempotency_token), - KEY index_inference_type (inference_type), + KEY index_inference_category (inference_category), + KEY index_maybe_model_type_and_maybe_model_token (maybe_model_type, maybe_model_token), + KEY index_maybe_model_type (maybe_model_type), KEY fk_maybe_model_token (maybe_model_token), KEY fk_on_success_result_entity_token (on_success_result_entity_token), KEY fk_maybe_creator_user_token (maybe_creator_user_token),