Skip to content

Commit

Permalink
Updating migration to run from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
rootelement committed Jul 28, 2020
1 parent 0235a16 commit 7ce682d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions data_migration/src/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const sequelize = new Sequelize(config.get('POSTGRES_URL'), {
logging: false
})

const SYNC_START_DATE = '2020-01-01'
// const SYNC_START_DATE = '2020-01-01'

async function migrateUserTerms () {
async function migrateUserTerms (startDate) {
const informixTableName = 'user_terms_of_use_xref'
const databaseName = 'common_oltp'
let running = true
Expand All @@ -29,7 +29,7 @@ async function migrateUserTerms () {
if (data.length < 1) running = false
for (let i = 0; i < data.length; i += 1) {
const termsOfUseId = data[i].terms_of_use_id
const userQuery = `select * from ${informixTableName} WHERE terms_of_use_id = ${termsOfUseId} AND create_date > DATE("${SYNC_START_DATE}") order by user_id asc`
const userQuery = `select * from ${informixTableName} WHERE terms_of_use_id = ${termsOfUseId} AND create_date > DATE("${startDate}") order by user_id asc`
// logger.debug(`userQuery ${JSON.stringify(userQuery)}`)
const userData = await executeQueryAsync(databaseName, userQuery)
const oldIds = userData.map(r => r.user_id)
Expand All @@ -42,7 +42,7 @@ async function migrateUserTerms () {

const postgresTermsOfUseQuery = `select ux.*, tu."legacyId" from ${config.DB_SCHEMA_NAME}."UserTermsOfUseXref" ux
left join ${config.DB_SCHEMA_NAME}."TermsOfUse" tu on ux."termsOfUseId" = tu.id
where ux.created > '${SYNC_START_DATE}' AND tu."legacyId" = ${termsOfUseId}`
where ux.created > '${startDate}' AND tu."legacyId" = ${termsOfUseId}`

// logger.debug(`postgres ${JSON.stringify(postgresTermsOfUseQuery)}`)
// const newUserTerms = await UserTermsOfUseXref.findAll(postgresTermsOfUseQuery)
Expand All @@ -66,6 +66,11 @@ async function migrateUserTerms () {
// logger.debug(`Finding ${JSON.stringify({ user_id: id })} in ${JSON.stringify(userData)}`)
const obj = find(userData, { user_id: id })
// logger.debug(`Found ${JSON.stringify(obj.create_date)}`)
logger.debug(`Creating Entry: ${JSON.stringify({
userId: id,
termsOfUseId: infoResult[0].id,
created: obj.create_date
})}`)
await UserTermsOfUseXref.create({
userId: id,
termsOfUseId: infoResult[0].id,
Expand All @@ -78,8 +83,8 @@ async function migrateUserTerms () {
} else {
logger.debug(`No Records, Skipping id: ${data[i].terms_of_use_id}`)
}
// running = false
}

skip += data.length
}
}
Expand Down
5 changes: 3 additions & 2 deletions data_migration/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const steps = ['DocusignEnvelope', 'UserTermsOfUseXref']

async function sync () {
logger.debug('Run Sync!!!')
await syncService.migrateUserTerms()
// await syncService.migrateDocusignEnvelopes()
const startDate = '2000-01-01'
await syncService.migrateUserTerms(startDate)
// await syncService.migrateDocusignEnvelopes(startDate)
//get ids from UserTermsOfUseXref
// look up in postres
// if not, add
Expand Down

0 comments on commit 7ce682d

Please sign in to comment.