0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Unified migration logging styles

no issue

- all migrations should contain a logging message
- info for successful things, or warn if we deviated from what was
  expected for some reason
- also added some spacing to make them easier to read
This commit is contained in:
Daniel Lockyer 2021-02-18 17:34:34 +00:00
parent bf960bcecb
commit a2dd7c7f7d
No known key found for this signature in database
GPG key ID: FFBC6FA2A6F6ABC1
4 changed files with 10 additions and 7 deletions

View file

@ -1,9 +1,12 @@
const {chunk} = require('lodash');
const ObjectID = require('bson-objectid');
const {createTransactionalMigration} = require('../../utils');
const logging = require('../../../../../shared/logging');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Populating members_subscribe_events from members');
const allMembers = await knex.select(
'id as member_id',
'created_at'

View file

@ -1,4 +1,5 @@
const {addTable} = require('../../utils');
module.exports = addTable('members_login_events', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},

View file

@ -6,7 +6,9 @@ const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Populating members_status_events from members table');
await knex('members_status_events').del();
const allMembers = await knex.select(
'id as member_id',
'status as to_status',

View file

@ -159,8 +159,6 @@ function checkTables(transaction) {
}
}
const createLog = type => msg => logging[type](msg);
function createColumnMigration(...migrations) {
async function runColumnMigration(conn, migration) {
const {
@ -175,11 +173,10 @@ function createColumnMigration(...migrations) {
const hasColumn = await conn.schema.hasColumn(table, column);
const isInCorrectState = dbIsInCorrectState(hasColumn);
const log = createLog(isInCorrectState ? 'warn' : 'info');
log(`${operationVerb} ${table}.${column} column`);
if (!isInCorrectState) {
if (isInCorrectState) {
logging.warn(`${operationVerb} ${table}.${column} column - skipping as table is correct`);
} else {
logging.info(`${operationVerb} ${table}.${column} column`);
await operation(table, column, conn, columnDefinition);
}
}