|
|
@ -4,6 +4,8 @@ import { MetaTable } from '~/utils/globals'; |
|
|
|
|
|
|
|
|
|
|
|
const logger = new Logger('nc_046_comment_mentions'); |
|
|
|
const logger = new Logger('nc_046_comment_mentions'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BATCH_SIZE = 5000; |
|
|
|
|
|
|
|
|
|
|
|
const up = async (knex: Knex) => { |
|
|
|
const up = async (knex: Knex) => { |
|
|
|
await knex.schema.createTable(MetaTable.COMMENTS, (table) => { |
|
|
|
await knex.schema.createTable(MetaTable.COMMENTS, (table) => { |
|
|
|
table.string('id', 20).primary(); |
|
|
|
table.string('id', 20).primary(); |
|
|
@ -42,7 +44,7 @@ const up = async (knex: Knex) => { |
|
|
|
|
|
|
|
|
|
|
|
table.string('row_id', 255); |
|
|
|
table.string('row_id', 255); |
|
|
|
|
|
|
|
|
|
|
|
table.string('user_id', 255); |
|
|
|
table.string('user_id', 20); |
|
|
|
|
|
|
|
|
|
|
|
table.string('fk_model_id', 20); |
|
|
|
table.string('fk_model_id', 20); |
|
|
|
|
|
|
|
|
|
|
@ -70,7 +72,7 @@ const up = async (knex: Knex) => { |
|
|
|
|
|
|
|
|
|
|
|
table.string('source_id', 20); |
|
|
|
table.string('source_id', 20); |
|
|
|
|
|
|
|
|
|
|
|
table.string('fk_modal_id', 20); |
|
|
|
table.string('fk_model_id', 20); |
|
|
|
|
|
|
|
|
|
|
|
table.string('base_id', 128); |
|
|
|
table.string('base_id', 128); |
|
|
|
|
|
|
|
|
|
|
@ -83,7 +85,10 @@ const up = async (knex: Knex) => { |
|
|
|
|
|
|
|
|
|
|
|
logger.log('nc_046_comment_mentions: Tables Created'); |
|
|
|
logger.log('nc_046_comment_mentions: Tables Created'); |
|
|
|
|
|
|
|
|
|
|
|
knex |
|
|
|
try { |
|
|
|
|
|
|
|
logger.log('nc_046_comment_mentions: Fetching Data from Audit Table'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rows = await knex |
|
|
|
.select( |
|
|
|
.select( |
|
|
|
`${MetaTable.AUDIT}.id`, |
|
|
|
`${MetaTable.AUDIT}.id`, |
|
|
|
`${MetaTable.AUDIT}.row_id`, |
|
|
|
`${MetaTable.AUDIT}.row_id`, |
|
|
@ -102,17 +107,21 @@ const up = async (knex: Knex) => { |
|
|
|
MetaTable.USERS, |
|
|
|
MetaTable.USERS, |
|
|
|
`${MetaTable.AUDIT}.user`, |
|
|
|
`${MetaTable.AUDIT}.user`, |
|
|
|
`${MetaTable.USERS}.email`, |
|
|
|
`${MetaTable.USERS}.email`, |
|
|
|
) |
|
|
|
); |
|
|
|
.then(async (rows) => { |
|
|
|
|
|
|
|
if (!rows.length) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.log('nc_046_comment_mentions: Data from Audit Table Selected'); |
|
|
|
logger.log('nc_046_comment_mentions: Data from Audit Table fetched'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!rows.length) { |
|
|
|
|
|
|
|
logger.log( |
|
|
|
|
|
|
|
'nc_046_comment_mentions: No Data Found to Migrate from Audit Table', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
const formattedRows = rows.map((row) => ({ |
|
|
|
const formattedRows = rows.map((row) => ({ |
|
|
|
id: row.id, |
|
|
|
id: row.id, |
|
|
|
row_id: row.row_id, |
|
|
|
row_id: row.row_id, |
|
|
|
comment: row.description |
|
|
|
comment: (row.description ?? '') |
|
|
|
.substring(row.description.indexOf(':') + 1) |
|
|
|
.substring((row.description ?? '').indexOf(':') + 1) |
|
|
|
.trim(), |
|
|
|
.trim(), |
|
|
|
created_by: row.user_id, |
|
|
|
created_by: row.user_id, |
|
|
|
created_by_email: row.user_email, |
|
|
|
created_by_email: row.user_email, |
|
|
@ -123,12 +132,22 @@ const up = async (knex: Knex) => { |
|
|
|
updated_at: row.updated_at, |
|
|
|
updated_at: row.updated_at, |
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
logger.log('nc_046_comment_mentions: Data from Audit Table Formatted'); |
|
|
|
logger.log('nc_046_comment_mentions: Data from Audit Table formatted'); |
|
|
|
|
|
|
|
|
|
|
|
await knex(MetaTable.COMMENTS).insert(formattedRows); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.log('nc_046_comment_mentions: Data from Audit Table Migrated'); |
|
|
|
await knex.transaction(function (trx) { |
|
|
|
|
|
|
|
return knex |
|
|
|
|
|
|
|
.batchInsert(MetaTable.COMMENTS, formattedRows, BATCH_SIZE) |
|
|
|
|
|
|
|
.transacting(trx); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.log( |
|
|
|
|
|
|
|
'nc_046_comment_mentions: Data migrated from Audit Table to Comments Table', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
logger.error( |
|
|
|
|
|
|
|
'nc_046_comment_mentions: Error while migrating data from Audit Table', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const down = async (knex: Knex) => { |
|
|
|
const down = async (knex: Knex) => { |
|
|
|