Skip to content

Commit

Permalink
refactor(strapi): clone meta field to new pageMeta field
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer6497 committed Jan 10, 2025
1 parent 6304284 commit c104fec
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
50 changes: 50 additions & 0 deletions database/migrations/2025.01.09T00.00.00.copy-meta-to-pageMeta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";

/**
* what this migration is doing:
Copies data from meta fields in pages, form-flow-pages, result-pages, and vorab-check-pages
to their new pageMeta equivalents
uses weird .raw syntax as it's currently not possible to create an INSERT INTO ... SELECT statement
in knex
*/

async function up(knex) {
try {
const tables = [
"pages_cmps",
"form_flow_pages_cmps",
"result_pages_cmps",
"vorab_check_pages_cmps",
];
const inserts = tables.map((collectionType) => {
return knex(
knex.raw("?? (??, ??, ??, ??)", [
collectionType,
"entity_id",
"cmp_id",
"component_type",
"field",
]),
).insert(function () {
this.select(
"entity_id",
"cmp_id",
"component_type",
knex.raw("?", ["pageMeta"]),
)
.from(collectionType)
.where("field", "meta");
});
});
const results = await Promise.all(inserts);
results.forEach((result, idx) =>
console.log(`${result.rowCount} rows inserted into table ${tables[idx]}.`),
);
} catch (error) {
console.log("error occured during migration. Skipping migration");
console.log(error);
}
}

module.exports = { up };
11 changes: 11 additions & 0 deletions src/api/form-flow-page/content-types/form-flow-page/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
}
},
"attributes": {
"pageMeta": {
"type": "component",
"repeatable": false,
"component": "page.meta-page-info",
"required": true,
"pluginOptions": {
"i18n": {
"localized": true
}
}
},
"meta": {
"type": "component",
"repeatable": false,
Expand Down
11 changes: 11 additions & 0 deletions src/api/page/content-types/page/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
"unique": false,
"required": true
},
"pageMeta": {
"type": "component",
"repeatable": false,
"pluginOptions": {
"i18n": {
"localized": true
}
},
"component": "page.meta-page-info",
"required": true
},
"meta": {
"type": "component",
"repeatable": false,
Expand Down
11 changes: 11 additions & 0 deletions src/api/result-page/content-types/result-page/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
}
},
"attributes": {
"pageMeta": {
"type": "component",
"repeatable": false,
"pluginOptions": {
"i18n": {
"localized": true
}
},
"component": "page.meta-page-info",
"required": true
},
"meta": {
"type": "component",
"repeatable": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
}
},
"attributes": {
"pageMeta": {
"type": "component",
"repeatable": false,
"component": "page.meta-page-info",
"required": true,
"pluginOptions": {
"i18n": {
"localized": true
}
}
},
"meta": {
"type": "component",
"repeatable": false,
Expand Down
28 changes: 28 additions & 0 deletions types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,13 @@ export interface ApiFormFlowPageFormFlowPage
localized: true;
};
}>;
pageMeta: Schema.Attribute.Component<'page.meta-page-info', false> &
Schema.Attribute.Required &
Schema.Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
post_form: Schema.Attribute.DynamicZone<
[
'basic.heading',
Expand Down Expand Up @@ -829,6 +836,13 @@ export interface ApiPagePage extends Struct.CollectionTypeSchema {
localized: true;
};
}>;
pageMeta: Schema.Attribute.Component<'page.meta-page-info', false> &
Schema.Attribute.Required &
Schema.Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
publishedAt: Schema.Attribute.DateTime;
slug: Schema.Attribute.String &
Schema.Attribute.Required &
Expand Down Expand Up @@ -922,6 +936,13 @@ export interface ApiResultPageResultPage extends Struct.CollectionTypeSchema {
'oneToOne',
'api::element-with-id.element-with-id'
>;
pageMeta: Schema.Attribute.Component<'page.meta-page-info', false> &
Schema.Attribute.Required &
Schema.Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
pageType: Schema.Attribute.Enumeration<
['error', 'success', 'warning', 'info']
> &
Expand Down Expand Up @@ -1049,6 +1070,13 @@ export interface ApiVorabCheckPageVorabCheckPage
localized: true;
};
}>;
pageMeta: Schema.Attribute.Component<'page.meta-page-info', false> &
Schema.Attribute.Required &
Schema.Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
pre_form: Schema.Attribute.DynamicZone<
[
'basic.heading',
Expand Down

0 comments on commit c104fec

Please sign in to comment.