Skip to content

Commit 7d9152a

Browse files
committed
Lint
1 parent a43cefa commit 7d9152a

21 files changed

+6412
-299
lines changed
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const { chain } = require('stream-chain');
4-
const { parser } = require('stream-json');
5-
const { streamArray } = require('stream-json/streamers/StreamArray');
1+
const fs = require('fs')
2+
const { chain } = require('stream-chain')
3+
const { parser } = require('stream-json')
4+
const { streamArray } = require('stream-json/streamers/StreamArray')
65

7-
async function loadJSON(filePath) {
6+
async function loadJSON (filePath) {
87
return new Promise((resolve, reject) => {
98
const pipeline = chain([
109
fs.createReadStream(filePath),
1110
parser(),
1211
streamArray()
13-
]);
12+
])
1413

15-
const result = [];
14+
const result = []
1615

17-
pipeline.on('data', ({ value }) => result.push(value));
18-
pipeline.on('end', () => resolve(result));
19-
pipeline.on('error', (err) => reject(err));
20-
});
16+
pipeline.on('data', ({ value }) => result.push(value))
17+
pipeline.on('end', () => resolve(result))
18+
pipeline.on('error', (err) => reject(err))
19+
})
2120
}
2221

2322
module.exports = {
24-
loadJSON,
25-
};
26-
23+
loadJSON
24+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const { PrismaClient } = require('@prisma/client');
1+
const { PrismaClient } = require('@prisma/client')
22

3-
const prisma = new PrismaClient();
4-
5-
module.exports = prisma;
3+
const prisma = new PrismaClient()
64

5+
module.exports = prisma

migrator/src/index.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
require('dotenv').config();
2-
const path = require('path');
3-
const fs = require('fs');
1+
require('dotenv').config()
2+
const path = require('path')
3+
const fs = require('fs')
44

55
// === MIGRATOR IMPORTS ===
66
// Import migration functions for each data type
77
// The 'Auto' versions dynamically choose between batch and simple migration
88
// based on the size of the input file (optimized for large datasets)
9-
const { migrateMemberProfilesAuto } = require('./migrators/migrateMemberProfileAuto'); // Large dataset
10-
const { migrateMemberStatsAuto } = require('./migrators/migrateMemberStatsAuto'); // Large dataset
11-
const { migrateResourceRoles } = require('./migrators/migrateResourceRole');
12-
const { migrateResourceRolePhaseDependencies } = require('./migrators/migrateResourceRolePhaseDependency');
13-
const { migrateResourceAuto } = require('./migrators/migrateResourceAuto'); // Large dataset (line-based JSON from ElasticSearch)
9+
const { migrateMemberProfilesAuto } = require('./migrators/migrateMemberProfileAuto') // Large dataset
10+
const { migrateMemberStatsAuto } = require('./migrators/migrateMemberStatsAuto') // Large dataset
11+
const { migrateResourceRoles } = require('./migrators/migrateResourceRole')
12+
const { migrateResourceRolePhaseDependencies } = require('./migrators/migrateResourceRolePhaseDependency')
13+
const { migrateResourceAuto } = require('./migrators/migrateResourceAuto') // Large dataset (line-based JSON from ElasticSearch)
1414

1515
// === MIGRATION STEPS ===
1616
// Map each step name to its corresponding function.
1717
// Each function logs execution time and calls its migrator.
1818
const steps = {
19-
// 'member-profiles': async (filePath) => {
20-
// const start = Date.now();
21-
// await migrateMemberProfilesAuto(filePath);
22-
// console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`);
23-
// },
24-
// 'member-stats': async (filePath) => {
25-
// const start = Date.now();
26-
// await migrateMemberStatsAuto(filePath);
27-
// console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`);
28-
// },
29-
// 'resource-roles': async (filePath) => {
30-
// const start = Date.now();
31-
// await migrateResourceRoles(filePath);
32-
// console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`);
33-
// },
34-
// 'resource-role-phase-dependencies': async (filePath) => {
35-
// const start = Date.now();
36-
// await migrateResourceRolePhaseDependencies(filePath);
37-
// console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`);
38-
// },
19+
'member-profiles': async (filePath) => {
20+
const start = Date.now()
21+
await migrateMemberProfilesAuto(filePath)
22+
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`)
23+
},
24+
'member-stats': async (filePath) => {
25+
const start = Date.now()
26+
await migrateMemberStatsAuto(filePath)
27+
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`)
28+
},
29+
'resource-roles': async (filePath) => {
30+
const start = Date.now()
31+
await migrateResourceRoles(filePath)
32+
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`)
33+
},
34+
'resource-role-phase-dependencies': async (filePath) => {
35+
const start = Date.now()
36+
await migrateResourceRolePhaseDependencies(filePath)
37+
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`)
38+
},
3939
'resources': async (filePath) => {
40-
const start = Date.now();
41-
await migrateResourceAuto(filePath);
42-
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`);
40+
const start = Date.now()
41+
await migrateResourceAuto(filePath)
42+
console.log(`⏱️ Duration: ${((Date.now() - start) / 1000).toFixed(2)}s.`)
4343
}
4444
};
4545

4646
// === EXECUTION ENTRYPOINT ===
4747
// Determines which migration step to execute and handles file path input
4848
(async () => {
49-
const step = process.argv[2]; // First argument: migration step name
50-
const customPath = process.argv[3]; // Second argument (optional): custom file path
49+
const step = process.argv[2] // First argument: migration step name
50+
const customPath = process.argv[3] // Second argument (optional): custom file path
5151

5252
// Default file paths for each step
5353
const defaultPaths = {
@@ -56,32 +56,32 @@ const steps = {
5656
'resource-roles': './data/ResourceRole_dynamo_data.json',
5757
'resource-role-phase-dependencies': './data/ResourceRolePhaseDependency_dynamo_data.json',
5858
'resources': './data/Resource_data.json'
59-
};
59+
}
6060

6161
// Show help if step is invalid
6262
if (!steps[step]) {
63-
console.log('❌ Invalid migration step.\nUsage:');
64-
console.log(' node src/index.js <step-name> [custom-path]');
65-
console.log('\nAvailable steps:');
66-
console.log(Object.keys(steps).map(s => ` - ${s}`).join('\n'));
67-
process.exit(1);
63+
console.log('❌ Invalid migration step.\nUsage:')
64+
console.log(' node src/index.js <step-name> [custom-path]')
65+
console.log('\nAvailable steps:')
66+
console.log(Object.keys(steps).map(s => ` - ${s}`).join('\n'))
67+
process.exit(1)
6868
}
6969

70-
const filePath = customPath || path.join(defaultPaths[step]);
70+
const filePath = customPath || path.join(defaultPaths[step])
7171

7272
// Validate file existence
7373
if (!fs.existsSync(filePath)) {
74-
console.error(`❌ File not found: ${filePath}`);
75-
process.exit(1);
74+
console.error(`❌ File not found: ${filePath}`)
75+
process.exit(1)
7676
}
7777

7878
// Run selected migration step
7979
try {
80-
console.log(`🚀 Starting ${step} migration from ${filePath}`);
81-
await steps[step](filePath);
82-
console.log(`Step '${step}' completed successfully.`);
80+
console.log(`🚀 Starting ${step} migration from ${filePath}`)
81+
await steps[step](filePath)
82+
console.log(`Step '${step}' completed successfully.`)
8383
} catch (error) {
84-
console.error(`❌ Error during '${step}':`, error.message);
85-
process.exit(1);
84+
console.error(`❌ Error during '${step}':`, error.message)
85+
process.exit(1)
8686
}
87-
})();
87+
})()

migrator/src/migrators/migrateMemberProfile.js

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,56 @@
22
* Simple (in-memory) migration strategy.
33
*
44
* This migrator loads the entire JSON file into memory using `loadJSON()` from the local utility.
5-
*
5+
*
66
* It is suitable for small datasets (e.g., test files, mocks), as it prioritizes clarity and simplicity over memory efficiency.
77
*/
88

9-
const fs = require('fs');
10-
const { loadJSON } = require('../clients/dynamoLoader');
11-
const prisma = require('../clients/prismaClient');
9+
const fs = require('fs')
10+
const { loadJSON } = require('../clients/dynamoLoader')
11+
const prisma = require('../clients/prismaClient')
1212

13-
async function migrateMemberProfiles(filePath) {
14-
const profiles = await loadJSON(filePath);
13+
async function migrateMemberProfiles (filePath) {
14+
const profiles = await loadJSON(filePath)
1515

16-
let successCount = 0;
17-
let failCount = 0;
16+
let successCount = 0
17+
let failCount = 0
1818

1919
for (const profile of profiles) {
2020
try {
21-
const createdBy = profile.createdBy || process.env.CREATED_BY;
22-
23-
await prisma.memberProfile.upsert({
24-
where: { userId: profile.userId },
25-
update: {
26-
handle: profile.handle || null,
27-
handleLower: profile.handleLower || null,
28-
email: profile.email || null,
29-
createdAt: profile.createdAt ? new Date(profile.createdAt) : new Date(),
30-
updatedAt: profile.updatedAt ? new Date(profile.updatedAt) : null,
31-
createdBy,
32-
updatedBy: profile.updatedBy || null
33-
},
34-
create: {
35-
userId: profile.userId,
36-
handle: profile.handle || null,
37-
handleLower: profile.handleLower || null,
38-
email: profile.email || null,
39-
createdAt: profile.createdAt ? new Date(profile.createdAt) : new Date(),
40-
updatedAt: profile.updatedAt ? new Date(profile.updatedAt) : null,
41-
createdBy,
42-
updatedBy: profile.updatedBy || null
43-
}
44-
});
45-
46-
successCount++;
21+
const createdBy = profile.createdBy || process.env.CREATED_BY
22+
23+
await prisma.memberProfile.upsert({
24+
where: { userId: profile.userId },
25+
update: {
26+
handle: profile.handle || null,
27+
handleLower: profile.handleLower || null,
28+
email: profile.email || null,
29+
createdAt: profile.createdAt ? new Date(profile.createdAt) : new Date(),
30+
updatedAt: profile.updatedAt ? new Date(profile.updatedAt) : null,
31+
createdBy,
32+
updatedBy: profile.updatedBy || null
33+
},
34+
create: {
35+
userId: profile.userId,
36+
handle: profile.handle || null,
37+
handleLower: profile.handleLower || null,
38+
email: profile.email || null,
39+
createdAt: profile.createdAt ? new Date(profile.createdAt) : new Date(),
40+
updatedAt: profile.updatedAt ? new Date(profile.updatedAt) : null,
41+
createdBy,
42+
updatedBy: profile.updatedBy || null
43+
}
44+
})
45+
46+
successCount++
4747
} catch (err) {
48-
failCount++;
49-
const message = err.message.split('\n').at(-1);
50-
fs.appendFileSync('logs/memberprofile_errors.log', `id=${profile.id} - ${message}\n`);
48+
failCount++
49+
const message = err.message.split('\n').at(-1)
50+
fs.appendFileSync('logs/memberprofile_errors.log', `id=${profile.id} - ${message}\n`)
5151
}
5252
}
5353

54-
console.log(`✅ MemberProfile migration finished: ${successCount} success, ${failCount} failed`);
54+
console.log(`✅ MemberProfile migration finished: ${successCount} success, ${failCount} failed`)
5555
}
5656

57-
module.exports = { migrateMemberProfiles };
58-
57+
module.exports = { migrateMemberProfiles }

migrator/src/migrators/migrateMemberProfileAuto.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
* This approach ensures performance and memory efficiency when handling real-world data.
1111
*/
1212

13-
const fs = require('fs');
14-
const { migrateMemberProfiles } = require('./migrateMemberProfile');
15-
const { migrateMemberProfiles: migrateBatch } = require('./migrateMemberProfileBatch');
13+
const fs = require('fs')
14+
const { migrateMemberProfiles } = require('./migrateMemberProfile')
15+
const { migrateMemberProfiles: migrateBatch } = require('./migrateMemberProfileBatch')
1616

17-
const FILE_SIZE_THRESHOLD = 3 * 1024 * 1024; // 3 MB
17+
const FILE_SIZE_THRESHOLD = 3 * 1024 * 1024 // 3 MB
1818

19-
async function migrateMemberProfilesAuto(filePath) {
20-
const stats = fs.statSync(filePath);
21-
const fileSize = stats.size;
19+
async function migrateMemberProfilesAuto (filePath) {
20+
const stats = fs.statSync(filePath)
21+
const fileSize = stats.size
2222

2323
if (fileSize < FILE_SIZE_THRESHOLD) {
2424
// Using normal migration (in-memory)
25-
await migrateMemberProfiles(filePath);
25+
await migrateMemberProfiles(filePath)
2626
} else {
2727
// Using batch migration (streaming)
28-
await migrateBatch(filePath);
28+
await migrateBatch(filePath)
2929
}
3030
}
3131

32-
module.exports = { migrateMemberProfilesAuto };
32+
module.exports = { migrateMemberProfilesAuto }

0 commit comments

Comments
 (0)