diff --git a/packages/strapi-plugin-i18n/config/functions/migrations/__tests__/field.test.js b/packages/strapi-plugin-i18n/config/functions/migrations/__tests__/field.test.js index 2fa1d029d9..43c046d7cb 100644 --- a/packages/strapi-plugin-i18n/config/functions/migrations/__tests__/field.test.js +++ b/packages/strapi-plugin-i18n/config/functions/migrations/__tests__/field.test.js @@ -31,10 +31,7 @@ describe('i18n - Migration - disable localization on a field', () => { test("Doesn't migrate if no attribute changed (without i18n)", async () => { const find = jest.fn(); - const getLocalizedAttributes = jest - .fn() - .mockReturnValueOnce([]) - .mockReturnValueOnce([]); + const getLocalizedAttributes = jest.fn(() => []); global.strapi = { query: () => { @@ -62,10 +59,7 @@ describe('i18n - Migration - disable localization on a field', () => { test("Doesn't migrate if no attribute changed (with i18n)", async () => { const find = jest.fn(); - const getLocalizedAttributes = jest - .fn() - .mockReturnValueOnce(['name']) - .mockReturnValueOnce(['name']); + const getLocalizedAttributes = jest.fn(() => ['name']); global.strapi = { query: () => { find; diff --git a/packages/strapi-plugin-i18n/config/functions/migrations/field/migrate-for-bookshelf.js b/packages/strapi-plugin-i18n/config/functions/migrations/field/migrate-for-bookshelf.js index 796e029737..13f403c407 100644 --- a/packages/strapi-plugin-i18n/config/functions/migrations/field/migrate-for-bookshelf.js +++ b/packages/strapi-plugin-i18n/config/functions/migrations/field/migrate-for-bookshelf.js @@ -48,7 +48,7 @@ const updateFromTmpTable = async ({ model, trx, attributesToMigrate }) => { const createTmpTable = async ({ ORM, attributesToMigrate, model }) => { const columnsToCopy = ['id', ...attributesToMigrate]; - await ORM.knex.schema.dropTableIfExists(TMP_TABLE_NAME); + await deleteTmpTable({ ORM }); await ORM.knex.raw(`CREATE TABLE ?? AS ??`, [ TMP_TABLE_NAME, ORM.knex @@ -65,8 +65,9 @@ const getSortedLocales = async trx => { try { const defaultLocaleRow = await trx('core_store') .select('value') - .where({ key: 'plugin_i18n_default_locale' }); - defaultLocale = defaultLocaleRow[0].value; + .where({ key: 'plugin_i18n_default_locale' }) + .first(); + defaultLocale = JSON.parse(defaultLocaleRow.value); } catch (e) { throw new Error("Could not migrate because the default locale doesn't exist"); }