feature(database): account for persisted tables in schema diffing

This commit is contained in:
Jamie Howard 2023-03-15 11:02:44 +00:00
parent 32d019ecbe
commit d3c6a7c927

View File

@ -2,7 +2,11 @@
const _ = require('lodash/fp'); const _ = require('lodash/fp');
const RESERVED_TABLE_NAMES = ['strapi_migrations', 'strapi_database_schema']; const RESERVED_TABLE_NAMES = [
'strapi_migrations',
'strapi_database_schema',
'strapi_reserved_table_names',
];
const statuses = { const statuses = {
CHANGED: 'CHANGED', CHANGED: 'CHANGED',
@ -322,7 +326,7 @@ module.exports = (db) => {
}; };
}; };
const diffSchemas = (srcSchema, destSchema) => { const diffSchemas = async (srcSchema, destSchema) => {
const addedTables = []; const addedTables = [];
const updatedTables = []; const updatedTables = [];
const unchangedTables = []; const unchangedTables = [];
@ -344,11 +348,18 @@ module.exports = (db) => {
} }
} }
const reservedTablesFromDB = await db
.getConnection()
.select('name')
.from('strapi_reserved_table_names');
const reservedTables = [
...RESERVED_TABLE_NAMES,
...reservedTablesFromDB.map((entry) => entry.name),
];
for (const srcTable of srcSchema.tables) { for (const srcTable of srcSchema.tables) {
if ( if (!helpers.hasTable(destSchema, srcTable.name) && !reservedTables.includes(srcTable.name)) {
!helpers.hasTable(destSchema, srcTable.name) &&
!RESERVED_TABLE_NAMES.includes(srcTable.name)
) {
removedTables.push(srcTable); removedTables.push(srcTable);
} }
} }