0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Improved readability of log messages during migrations

- this commit removes the colons from the log messages to make each
  line flow easier when you're reading it
- also removes a couple of superfluous words that aren't needed
This commit is contained in:
Daniel Lockyer 2022-04-01 08:57:48 +01:00
parent 4f7324f1c0
commit 218950739d
No known key found for this signature in database
GPG key ID: D21186F0B47295AD

View file

@ -80,18 +80,18 @@ function dropColumn(tableName, column, transaction = db.knex) {
*/
async function addUnique(tableName, columns, transaction = db.knex) {
try {
logging.info(`Adding unique constraint for: ${columns} in table ${tableName}`);
logging.info(`Adding unique constraint for '${columns}' in table '${tableName}'`);
return await transaction.schema.table(tableName, function (table) {
table.unique(columns);
});
} catch (err) {
if (err.code === 'SQLITE_ERROR') {
logging.warn(`Constraint for: ${columns} already exists for table: ${tableName}`);
logging.warn(`Constraint for '${columns}' already exists for table '${tableName}'`);
return;
}
if (err.code === 'ER_DUP_KEYNAME') {
logging.warn(`Constraint for: ${columns} already exists for table: ${tableName}`);
logging.warn(`Constraint for '${columns}' already exists for table '${tableName}'`);
return;
}
throw err;
@ -107,18 +107,18 @@ async function addUnique(tableName, columns, transaction = db.knex) {
*/
async function dropUnique(tableName, columns, transaction = db.knex) {
try {
logging.info(`Dropping unique constraint for: ${columns} in table: ${tableName}`);
logging.info(`Dropping unique constraint for '${columns}' in table '${tableName}'`);
return await transaction.schema.table(tableName, function (table) {
table.dropUnique(columns);
});
} catch (err) {
if (err.code === 'SQLITE_ERROR') {
logging.warn(`Constraint for: ${columns} does not exist for table: ${tableName}`);
logging.warn(`Constraint for '${columns}' does not exist for table '${tableName}'`);
return;
}
if (err.code === 'ER_CANT_DROP_FIELD_OR_KEY') {
logging.warn(`Constraint for: ${columns} does not exist for table: ${tableName}`);
logging.warn(`Constraint for '${columns}' does not exist for table '${tableName}'`);
return;
}
throw err;
@ -164,7 +164,7 @@ async function addForeign({fromTable, fromColumn, toTable, toColumn, cascadeDele
if (DatabaseInfo.isSQLite(transaction)) {
const foreignKeyExists = await hasForeignSQLite({fromTable, fromColumn, toTable, toColumn, transaction});
if (foreignKeyExists) {
logging.warn(`Skipped adding foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - foreign key already exists`);
logging.warn(`Skipped adding foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - already exists`);
return;
}
}
@ -195,7 +195,7 @@ async function addForeign({fromTable, fromColumn, toTable, toColumn, cascadeDele
}
} catch (err) {
if (err.code === 'ER_DUP_KEY' || err.code === 'ER_FK_DUP_KEY' || err.code === 'ER_FK_DUP_NAME') {
logging.warn(`Skipped adding foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - foreign key already exists`);
logging.warn(`Skipped adding foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - already exists`);
return;
}
throw err;
@ -216,7 +216,7 @@ async function dropForeign({fromTable, fromColumn, toTable, toColumn, transactio
if (DatabaseInfo.isSQLite(transaction)) {
const foreignKeyExists = await hasForeignSQLite({fromTable, fromColumn, toTable, toColumn, transaction});
if (!foreignKeyExists) {
logging.warn(`Skipped dropping foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - foreign key does not exist`);
logging.warn(`Skipped dropping foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - does not exist`);
return;
}
}
@ -243,7 +243,7 @@ async function dropForeign({fromTable, fromColumn, toTable, toColumn, transactio
}
} catch (err) {
if (err.code === 'ER_CANT_DROP_FIELD_OR_KEY') {
logging.warn(`Skipped dropping foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - foreign key does not exist`);
logging.warn(`Skipped dropping foreign key from ${fromTable}.${fromColumn} to ${toTable}.${toColumn} - does not exist`);
return;
}
throw err;
@ -280,18 +280,18 @@ async function addPrimaryKey(tableName, columns, transaction = db.knex) {
if (DatabaseInfo.isSQLite(transaction)) {
const primaryKeyExists = await hasPrimaryKeySQLite(tableName, transaction);
if (primaryKeyExists) {
logging.warn(`Primary key constraint for: ${columns} already exists for table: ${tableName}`);
logging.warn(`Primary key constraint for '${columns}' already exists for table '${tableName}'`);
return;
}
}
try {
logging.info(`Adding primary key constraint for: ${columns} in table ${tableName}`);
logging.info(`Adding primary key constraint for '${columns}' in table '${tableName}'`);
return await transaction.schema.table(tableName, function (table) {
table.primary(columns);
});
} catch (err) {
if (err.code === 'ER_MULTIPLE_PRI_KEY') {
logging.warn(`Primary key constraint for: ${columns} already exists for table: ${tableName}`);
logging.warn(`Primary key constraint for '${columns}' already exists for table '${tableName}'`);
return;
}
throw err;