From e6810313d92248e9e4adb6249005e3e654880670 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 14 Apr 2024 12:36:23 +0200 Subject: [PATCH] app-backend: fix asset store indexing for MySQL Signed-off-by: Patrik Oldsberg --- .../20240113144027_assets-namespace.js | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/plugins/app-backend/migrations/20240113144027_assets-namespace.js b/plugins/app-backend/migrations/20240113144027_assets-namespace.js index de6ca2e333..6e94ac1531 100644 --- a/plugins/app-backend/migrations/20240113144027_assets-namespace.js +++ b/plugins/app-backend/migrations/20240113144027_assets-namespace.js @@ -20,29 +20,63 @@ * @param {import('knex').Knex} knex */ exports.up = async function up(knex) { + const isMySQL = knex.client.config.client.includes('mysql'); + await knex.schema.alterTable('static_assets_cache', table => { // The namespace is used to allow operations on asset groups, e.g. delete all assets in a namespace table .string('namespace') .defaultTo('default') .comment('The namespace of the file'); - table.dropPrimary(); - table.primary(['namespace', 'path']); + + if (!isMySQL) { + table.dropPrimary(); + table.primary(['namespace', 'path']); + } }); + + if (isMySQL) { + await knex.schema.raw( + 'drop index static_assets_cache_path_idx on static_assets_cache;', + ); + await knex.schema.raw( + 'create unique index static_assets_cache_path_idx on static_assets_cache(namespace, path(254));', + ); + } }; /** * @param {import('knex').Knex} knex */ exports.down = async function down(knex) { + const isMySQL = knex.client.config.client.includes('mysql'); + await knex .delete() .from('static_assets_cache') .whereNot('namespace', 'default'); + if (isMySQL) { + await knex.schema.raw( + 'drop index static_assets_cache_path_idx on static_assets_cache;', + ); + } + await knex.schema.alterTable('static_assets_cache', table => { - table.dropPrimary(); + if (!isMySQL) { + table.dropPrimary(); + } + table.dropColumn('namespace'); - table.primary(['path']); + + if (!isMySQL) { + table.primary(['path']); + } }); + + if (isMySQL) { + await knex.schema.raw( + 'create unique index static_assets_cache_path_idx on static_assets_cache(path(254));', + ); + } };