mirror of
https://github.com/strapi/strapi.git
synced 2025-11-23 21:53:05 +00:00
fix: v5 migration does not link locales (#21050)
* chore: avoid using identifiers utils * Update packages/core/database/src/migrations/internal-migrations/5.0.0-02-document-id.ts Co-authored-by: Ben Irvin <ben.irvin@strapi.io> * fix: prettier --------- Co-authored-by: Ben Irvin <ben.irvin@strapi.io>
This commit is contained in:
parent
8d950c6dc5
commit
9c9ad857af
@ -1,10 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* NOTE: This migration avoids using the `identifiers` utility.
|
||||||
|
* As the `5.0.0-01-convert-identifiers-long-than-max-length`
|
||||||
|
* migration does not convert the `localizations` join tables, as they are not
|
||||||
|
* tables that exist anymore in v5 and are not in the db metadata.
|
||||||
|
*
|
||||||
|
* This migration therefore relies on the fact that those tables still exist, and
|
||||||
|
* references them directly.
|
||||||
|
*
|
||||||
|
* Database join table name: `categories_localizations_links`
|
||||||
|
* Actual `identifiers` returned join table name: `categories_localizations_lnk`
|
||||||
|
*
|
||||||
|
*/
|
||||||
import { createId } from '@paralleldrive/cuid2';
|
import { createId } from '@paralleldrive/cuid2';
|
||||||
|
import { snakeCase } from 'lodash/fp';
|
||||||
import type { Knex } from 'knex';
|
import type { Knex } from 'knex';
|
||||||
|
|
||||||
import type { Migration } from '../common';
|
import type { Migration } from '../common';
|
||||||
import type { Database } from '../..';
|
import type { Database } from '../..';
|
||||||
import type { Meta } from '../../metadata';
|
import type { Meta } from '../../metadata';
|
||||||
import { identifiers } from '../../utils/identifiers';
|
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
joinColumn: string;
|
joinColumn: string;
|
||||||
@ -96,9 +109,8 @@ const getNextIdsToCreateDocumentId = async (
|
|||||||
// Migrate document ids for tables that have localizations
|
// Migrate document ids for tables that have localizations
|
||||||
const migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {
|
const migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {
|
||||||
const singularName = meta.singularName.toLowerCase();
|
const singularName = meta.singularName.toLowerCase();
|
||||||
const joinColumn = identifiers.getJoinColumnAttributeIdName(singularName);
|
const joinColumn = snakeCase(`${singularName}_id`);
|
||||||
const inverseJoinColumn = identifiers.getInverseJoinColumnAttributeIdName(singularName);
|
const inverseJoinColumn = snakeCase(`inv_${singularName}_id`);
|
||||||
|
|
||||||
let ids: number[];
|
let ids: number[];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -106,7 +118,7 @@ const migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, met
|
|||||||
joinColumn,
|
joinColumn,
|
||||||
inverseJoinColumn,
|
inverseJoinColumn,
|
||||||
tableName: meta.tableName,
|
tableName: meta.tableName,
|
||||||
joinTableName: identifiers.getJoinTableName(meta.tableName, `localizations`),
|
joinTableName: snakeCase(`${meta.tableName}_localizations_links`),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
@ -138,7 +150,7 @@ const createDocumentIdColumn = async (knex: Knex, tableName: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {
|
const hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {
|
||||||
const joinTableName = identifiers.getJoinTableName(tableName, 'localizations');
|
const joinTableName = snakeCase(`${tableName}_localizations_links`);
|
||||||
return knex.schema.hasTable(joinTableName);
|
return knex.schema.hasTable(joinTableName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user