-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
to-native-relation.ts
37 lines (32 loc) · 1014 Bytes
/
to-native-relation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import _ from 'lodash';
import { Schema } from '@strapi/strapi';
import { IStrapi } from '../../types/strapi';
const migrateToNativeRelation = (strapi: IStrapi) => {
Object.values(strapi.contentTypes).map(async (contentType: Schema.ContentType) => {
const notMigrated = _.get(contentType.pluginOptions, ['url-alias', 'enabled'], false) as boolean;
// Return when the migration is allready finished.
if (!notMigrated) {
return;
}
const pagesToBeMigrated = await strapi.entityService.findMany(contentType.uid, {
// @ts-ignore
fields: 'url_path_id',
filters: {
// @ts-ignore
url_path_id: {
$notNull: true,
},
},
});
pagesToBeMigrated.map(async (page) => {
await strapi.entityService.update(contentType.uid, page.id, {
data: {
// @ts-ignore
url_alias: Number(page.url_path_id),
url_path_id: null,
},
});
});
});
};
export default migrateToNativeRelation;