From c9bc7e20dc63614da91d77847356227397c08323 Mon Sep 17 00:00:00 2001 From: rcorvus <5025458+rcorvus@users.noreply.github.com> Date: Thu, 13 Aug 2026 20:00:27 -0700 Subject: [PATCH] fix(db): allow 'dataset' in installed_resources.resource_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The model declares `'zim' | 'map' | 'dataset'` and IngestDrugDataJob writes a 'dataset' row for the openFDA drug labels, but the column was still enum('zim','map') from the table's original migration. Every write failed: Data truncated for column 'resource_type' at row 1 insert into `installed_resources` (... `resource_type`, ...) values (..., 'openfda-drug-labels', 'dataset', ...) The ingest itself succeeded — 261,671 rows landed in drug_labels — but the install-state write-back at the end of the job was lost every time. Since getCategoriesWithStatus() resolves a tier only when every resource id is accounted for, and it already queries whereIn('resource_type', ['zim', 'dataset']), the missing row kept the Medicine category from ever resolving its Standard or Comprehensive tier. Only the enum was left behind. Verified against a live install: after the migration the previously failing insert succeeds, and Medicine resolves installedTierSlug 'medicine-comprehensive'. down() drops 'dataset' rows before narrowing the column, since MySQL would otherwise truncate them to '' or fail under STRICT_TRANS_TABLES. --- ...add_dataset_to_installed_resources_type.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 admin/database/migrations/1778800000001_add_dataset_to_installed_resources_type.ts diff --git a/admin/database/migrations/1778800000001_add_dataset_to_installed_resources_type.ts b/admin/database/migrations/1778800000001_add_dataset_to_installed_resources_type.ts new file mode 100644 index 0000000..c5e3a01 --- /dev/null +++ b/admin/database/migrations/1778800000001_add_dataset_to_installed_resources_type.ts @@ -0,0 +1,34 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' + +/** + * Widen `installed_resources.resource_type` to accept 'dataset'. + * + * The model already declares `'zim' | 'map' | 'dataset'` and + * `IngestDrugDataJob` writes a 'dataset' row for the openFDA drug labels, but + * the column was still `enum('zim','map')` from the table's original + * migration. Every write failed with "Data truncated for column + * 'resource_type'", so the drug reference ingested its 261k labels and then + * left no install-state row — the tier-status math and the home-tile gate both + * read those rows, so the resource stayed invisible to them. + */ +export default class extends BaseSchema { + protected tableName = 'installed_resources' + + async up() { + await this.db.rawQuery( + "ALTER TABLE installed_resources MODIFY COLUMN resource_type " + + "enum('zim','map','dataset') NOT NULL" + ) + } + + async down() { + // Rows that only exist because of this widening have to go before the + // column can be narrowed again; MySQL would otherwise truncate them to '' + // (or fail outright under STRICT_TRANS_TABLES). + await this.db.rawQuery("DELETE FROM installed_resources WHERE resource_type = 'dataset'") + await this.db.rawQuery( + "ALTER TABLE installed_resources MODIFY COLUMN resource_type " + + "enum('zim','map') NOT NULL" + ) + } +}