Use string column and stringifyEntityRef for location_entity_ref
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 <freben@spotify.com> Made-with: Cursor
This commit is contained in:
@@ -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-<sha1hex>',
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 | - |
|
||||
|
||||
|
||||
@@ -38,10 +38,11 @@ export function locationSpecToMetadataName(location: LocationSpec) {
|
||||
* stored location row, e.g. `location:default/generated-<sha1hex>`.
|
||||
*/
|
||||
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: {
|
||||
|
||||
Reference in New Issue
Block a user