From cb868c72750a7bf2cb0eb5e82d3cccdc0c9172e1 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 2 Jun 2025 05:02:10 -0400 Subject: [PATCH] add migrations and materialized final schema --- .../down.sql | 6 ++++++ .../up.sql | 9 +++++++++ .../down.sql | 9 +++++++++ .../up.sql | 11 +++++++++++ _sql/migrations_squashed/generic_inference_jobs.sql | 11 +++++++++++ 5 files changed, 46 insertions(+) create mode 100644 _sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/down.sql create mode 100644 _sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/up.sql create mode 100644 _sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/down.sql create mode 100644 _sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/up.sql diff --git a/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/down.sql b/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/down.sql new file mode 100644 index 0000000000..ed2247cec8 --- /dev/null +++ b/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/down.sql @@ -0,0 +1,6 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs DROP COLUMN maybe_external_third_party_id; +ALTER TABLE generic_inference_jobs DROP COLUMN maybe_external_third_party; diff --git a/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/up.sql b/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/up.sql new file mode 100644 index 0000000000..37351c649a --- /dev/null +++ b/_sql/migrations/2025-06-02-085011_jobs_add_third_party_columns/up.sql @@ -0,0 +1,9 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs +ADD COLUMN maybe_external_third_party VARCHAR(16) DEFAULT NULL; + +ALTER TABLE generic_inference_jobs +ADD COLUMN maybe_external_third_party_id VARCHAR(64) DEFAULT NULL; diff --git a/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/down.sql b/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/down.sql new file mode 100644 index 0000000000..6d7e40fd62 --- /dev/null +++ b/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/down.sql @@ -0,0 +1,9 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP INDEX `index_maybe_external_third_party_id` + ON `generic_inference_jobs`; + +DROP INDEX `index_maybe_external_third_party_and_id` + ON `generic_inference_jobs`; diff --git a/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/up.sql b/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/up.sql new file mode 100644 index 0000000000..8b9b663042 --- /dev/null +++ b/_sql/migrations/2025-06-02-085015_jobs_add_third_party_indices/up.sql @@ -0,0 +1,11 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE generic_inference_jobs + ADD UNIQUE INDEX index_maybe_external_third_party_and_id (maybe_external_third_party, maybe_external_third_party_id), + ALGORITHM=INPLACE, LOCK=NONE; + +ALTER TABLE generic_inference_jobs + ADD INDEX index_maybe_external_third_party_id (maybe_external_third_party_id), + ALGORITHM=INPLACE, LOCK=NONE; diff --git a/_sql/migrations_squashed/generic_inference_jobs.sql b/_sql/migrations_squashed/generic_inference_jobs.sql index a968cdcc82..3806c60029 100644 --- a/_sql/migrations_squashed/generic_inference_jobs.sql +++ b/_sql/migrations_squashed/generic_inference_jobs.sql @@ -41,6 +41,15 @@ CREATE TABLE generic_inference_jobs ( -- * voice_conversion inference_category VARCHAR(32) NOT NULL, + -- 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. + maybe_external_third_party VARCHAR(16) DEFAULT NULL, + + -- If the job is externally enqueued, this is the ID the third-party + -- service uses. + maybe_external_third_party_id VARCHAR(64) DEFAULT NULL, + -- There is an index on this column. -- NB: See notes on inference_category. This is becoming a problematic field. We're using -- this to load the container spin-up arguments and dependencies, but the former is being @@ -287,11 +296,13 @@ CREATE TABLE generic_inference_jobs ( PRIMARY KEY (id), UNIQUE KEY (token), UNIQUE KEY (uuid_idempotency_token), + UNIQUE KEY (maybe_external_third_party, maybe_external_third_party_id), KEY index_job_type (job_type), KEY index_product_category (product_category), 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 index_maybe_external_third_party_id (maybe_external_third_party_id), KEY fk_maybe_model_token (maybe_model_token), KEY fk_maybe_input_source_token (maybe_input_source_token), KEY fk_maybe_input_source_token_and_type (maybe_input_source_token, maybe_input_source_token_type),