-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(strapi): clone meta field to new pageMeta field
- Loading branch information
1 parent
6304284
commit c104fec
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
database/migrations/2025.01.09T00.00.00.copy-meta-to-pageMeta.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters