diff --git a/database/migrations/2025.01.09T00.00.00.copy-meta-to-pageMeta.js b/database/migrations/2025.01.09T00.00.00.copy-meta-to-pageMeta.js new file mode 100644 index 0000000..7cd7e80 --- /dev/null +++ b/database/migrations/2025.01.09T00.00.00.copy-meta-to-pageMeta.js @@ -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 }; diff --git a/src/api/form-flow-page/content-types/form-flow-page/schema.json b/src/api/form-flow-page/content-types/form-flow-page/schema.json index 1aaf968..2dff139 100644 --- a/src/api/form-flow-page/content-types/form-flow-page/schema.json +++ b/src/api/form-flow-page/content-types/form-flow-page/schema.json @@ -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, diff --git a/src/api/page/content-types/page/schema.json b/src/api/page/content-types/page/schema.json index f32c2c6..1d033d3 100644 --- a/src/api/page/content-types/page/schema.json +++ b/src/api/page/content-types/page/schema.json @@ -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, diff --git a/src/api/result-page/content-types/result-page/schema.json b/src/api/result-page/content-types/result-page/schema.json index 5d02b91..bbbfd04 100644 --- a/src/api/result-page/content-types/result-page/schema.json +++ b/src/api/result-page/content-types/result-page/schema.json @@ -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, diff --git a/src/api/vorab-check-page/content-types/vorab-check-page/schema.json b/src/api/vorab-check-page/content-types/vorab-check-page/schema.json index 7d30054..69b831c 100644 --- a/src/api/vorab-check-page/content-types/vorab-check-page/schema.json +++ b/src/api/vorab-check-page/content-types/vorab-check-page/schema.json @@ -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, diff --git a/types/generated/contentTypes.d.ts b/types/generated/contentTypes.d.ts index 7dcd1c4..7e7379c 100644 --- a/types/generated/contentTypes.d.ts +++ b/types/generated/contentTypes.d.ts @@ -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', @@ -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 & @@ -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'] > & @@ -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',