From b21576575dead70082d3a098aacb7bf419c7c63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Sat, 4 Apr 2026 22:24:36 +0200 Subject: [PATCH] Use string column and stringifyEntityRef for location_entity_ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch the migration column type from text to string (varchar(255)), since entity refs are always short. Also use stringifyEntityRef in computeLocationEntityRef to handle lowercasing canonically. Signed-off-by: Fredrik Adelöw Made-with: Cursor --- .../migrations/20260403000000_add_location_entity_ref.js | 4 ++-- plugins/catalog-backend/report.sql.md | 2 +- plugins/catalog-backend/src/util/conversion.ts | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/catalog-backend/migrations/20260403000000_add_location_entity_ref.js b/plugins/catalog-backend/migrations/20260403000000_add_location_entity_ref.js index f34240ce76..507c3a8e64 100644 --- a/plugins/catalog-backend/migrations/20260403000000_add_location_entity_ref.js +++ b/plugins/catalog-backend/migrations/20260403000000_add_location_entity_ref.js @@ -50,7 +50,7 @@ exports.up = async function up(knex) { // Step 1: Add column as nullable so the schema change itself needs no data. await knex.schema.alterTable('locations', table => { table - .text('location_entity_ref') + .string('location_entity_ref') .nullable() .comment( 'The entity ref of the corresponding Location kind entity, e.g. location:default/generated-', @@ -126,7 +126,7 @@ exports.up = async function up(knex) { // MySQL: MODIFY COLUMN rewrites the column definition. // SQLite: knex recreates the table to enforce the NOT NULL constraint. await knex.schema.alterTable('locations', table => { - table.text('location_entity_ref').notNullable().alter(); + table.string('location_entity_ref').notNullable().alter(); }); } }; diff --git a/plugins/catalog-backend/report.sql.md b/plugins/catalog-backend/report.sql.md index 56340ad620..62a384adc2 100644 --- a/plugins/catalog-backend/report.sql.md +++ b/plugins/catalog-backend/report.sql.md @@ -46,7 +46,7 @@ | Column | Type | Nullable | Max Length | Default | | --------------------- | ------------------- | -------- | ---------- | ------- | | `id` | `uuid` | false | - | - | -| `location_entity_ref` | `text` | false | - | - | +| `location_entity_ref` | `character varying` | false | 255 | - | | `target` | `text` | true | - | - | | `type` | `character varying` | false | 255 | - | diff --git a/plugins/catalog-backend/src/util/conversion.ts b/plugins/catalog-backend/src/util/conversion.ts index c499715db5..5f7371375e 100644 --- a/plugins/catalog-backend/src/util/conversion.ts +++ b/plugins/catalog-backend/src/util/conversion.ts @@ -38,10 +38,11 @@ export function locationSpecToMetadataName(location: LocationSpec) { * stored location row, e.g. `location:default/generated-`. */ export function computeLocationEntityRef(type: string, target: string): string { - return `location:default/${locationSpecToMetadataName({ - type, - target, - })}`.toLocaleLowerCase('en-US'); + return stringifyEntityRef({ + kind: 'Location', + namespace: 'default', + name: locationSpecToMetadataName({ type, target }), + }); } export function locationSpecToLocationEntity(opts: {