mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-25 01:15:26 +10:00
use vite+
This commit is contained in:
+361
-361
@@ -12,24 +12,24 @@ import { generateId } from "@/utils/string";
|
||||
type Visibility = "public" | "private";
|
||||
|
||||
interface ProductionResume {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
data: unknown; // JSON data
|
||||
visibility: Visibility;
|
||||
locked: boolean;
|
||||
userId: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
data: unknown; // JSON data
|
||||
visibility: Visibility;
|
||||
locked: boolean;
|
||||
userId: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
interface ProductionStatistics {
|
||||
id: string;
|
||||
views: number;
|
||||
downloads: number;
|
||||
resumeId: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
id: string;
|
||||
views: number;
|
||||
downloads: number;
|
||||
resumeId: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
const productionUrl = process.env.PRODUCTION_DATABASE_URL;
|
||||
@@ -62,444 +62,444 @@ const INSERT_CHUNK_SIZE = 1000;
|
||||
// == Progress checkpoint interface ==
|
||||
// Uses cursor-based pagination with (createdAt, id) composite key for efficiency
|
||||
interface MigrationProgress {
|
||||
// Cursor for pagination - last seen createdAt timestamp
|
||||
lastSeenCreatedAt: string | null;
|
||||
// Cursor for pagination - last seen id (for tiebreaker when timestamps are equal)
|
||||
lastSeenId: string | null;
|
||||
resumesCreated: number;
|
||||
statisticsCreated: number;
|
||||
skipped: number;
|
||||
totalResumesProcessed: number;
|
||||
errors: number;
|
||||
lastUpdated: string;
|
||||
// Cursor for pagination - last seen createdAt timestamp
|
||||
lastSeenCreatedAt: string | null;
|
||||
// Cursor for pagination - last seen id (for tiebreaker when timestamps are equal)
|
||||
lastSeenId: string | null;
|
||||
resumesCreated: number;
|
||||
statisticsCreated: number;
|
||||
skipped: number;
|
||||
totalResumesProcessed: number;
|
||||
errors: number;
|
||||
lastUpdated: string;
|
||||
}
|
||||
|
||||
// Flag to track if shutdown was requested
|
||||
let shutdownRequested = false;
|
||||
|
||||
async function loadProgress(): Promise<MigrationProgress | null> {
|
||||
try {
|
||||
const text = await fs.readFile(PROGRESS_FILE, { encoding: "utf-8" });
|
||||
const progress = JSON.parse(text) as MigrationProgress;
|
||||
console.log(`📂 Found existing progress file. Last updated: ${progress.lastUpdated}`);
|
||||
console.log(` Resuming from cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})...`);
|
||||
return progress;
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load progress file, starting from beginning.", e);
|
||||
}
|
||||
return null;
|
||||
try {
|
||||
const text = await fs.readFile(PROGRESS_FILE, { encoding: "utf-8" });
|
||||
const progress = JSON.parse(text) as MigrationProgress;
|
||||
console.log(`📂 Found existing progress file. Last updated: ${progress.lastUpdated}`);
|
||||
console.log(` Resuming from cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})...`);
|
||||
return progress;
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load progress file, starting from beginning.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function saveProgress(progress: MigrationProgress): Promise<void> {
|
||||
try {
|
||||
progress.lastUpdated = new Date().toISOString();
|
||||
await fs.writeFile(PROGRESS_FILE, JSON.stringify(progress, null, 2), { encoding: "utf-8" });
|
||||
console.log(`💾 Progress saved at cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})`);
|
||||
} catch (e) {
|
||||
console.error("🚨 Failed to save progress:", e);
|
||||
}
|
||||
try {
|
||||
progress.lastUpdated = new Date().toISOString();
|
||||
await fs.writeFile(PROGRESS_FILE, JSON.stringify(progress, null, 2), { encoding: "utf-8" });
|
||||
console.log(`💾 Progress saved at cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})`);
|
||||
} catch (e) {
|
||||
console.error("🚨 Failed to save progress:", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function clearProgress(): Promise<void> {
|
||||
try {
|
||||
await fs.unlink(PROGRESS_FILE);
|
||||
console.log("🗑️ Progress file cleared.");
|
||||
} catch {
|
||||
// Ignore errors when clearing
|
||||
}
|
||||
try {
|
||||
await fs.unlink(PROGRESS_FILE);
|
||||
console.log("🗑️ Progress file cleared.");
|
||||
} catch {
|
||||
// Ignore errors when clearing
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUserIdMapFromFile(): Promise<Map<string, string>> {
|
||||
try {
|
||||
const text = await fs.readFile(USER_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load userIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
try {
|
||||
const text = await fs.readFile(USER_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load userIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
}
|
||||
|
||||
async function loadResumeIdMapFromFile(): Promise<Map<string, string>> {
|
||||
try {
|
||||
const text = await fs.readFile(RESUME_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load resumeIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
try {
|
||||
const text = await fs.readFile(RESUME_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load resumeIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
}
|
||||
|
||||
async function saveResumeIdMapToFile(resumeIdMap: Map<string, string>) {
|
||||
const obj: Record<string, string> = Object.fromEntries(resumeIdMap.entries());
|
||||
await fs.writeFile(RESUME_ID_MAP_FILE, JSON.stringify(obj, null, "\t"), { encoding: "utf-8" });
|
||||
const obj: Record<string, string> = Object.fromEntries(resumeIdMap.entries());
|
||||
await fs.writeFile(RESUME_ID_MAP_FILE, JSON.stringify(obj, null, "\t"), { encoding: "utf-8" });
|
||||
}
|
||||
|
||||
export async function migrateResumes() {
|
||||
const migrationStart = performance.now();
|
||||
console.log("⌛ Starting resume migration...");
|
||||
const migrationStart = performance.now();
|
||||
console.log("⌛ Starting resume migration...");
|
||||
|
||||
let hasMore = true;
|
||||
let hasMore = true;
|
||||
|
||||
// Cursor-based pagination state
|
||||
let lastSeenCreatedAt: string | null = null;
|
||||
let lastSeenId: string | null = null;
|
||||
// Cursor-based pagination state
|
||||
let lastSeenCreatedAt: string | null = null;
|
||||
let lastSeenId: string | null = null;
|
||||
|
||||
// Load persistent ID maps from file
|
||||
const userIdMap = await loadUserIdMapFromFile();
|
||||
const resumeIdMap = await loadResumeIdMapFromFile();
|
||||
// Load persistent ID maps from file
|
||||
const userIdMap = await loadUserIdMapFromFile();
|
||||
const resumeIdMap = await loadResumeIdMapFromFile();
|
||||
|
||||
// Track migration stats
|
||||
let resumesCreated = 0;
|
||||
let statisticsCreated = 0;
|
||||
let skipped = 0;
|
||||
let totalResumesProcessed = 0;
|
||||
let errors = 0;
|
||||
// Track migration stats
|
||||
let resumesCreated = 0;
|
||||
let statisticsCreated = 0;
|
||||
let skipped = 0;
|
||||
let totalResumesProcessed = 0;
|
||||
let errors = 0;
|
||||
|
||||
// Load saved progress if exists
|
||||
const savedProgress = await loadProgress();
|
||||
if (savedProgress) {
|
||||
lastSeenCreatedAt = savedProgress.lastSeenCreatedAt;
|
||||
lastSeenId = savedProgress.lastSeenId;
|
||||
resumesCreated = savedProgress.resumesCreated;
|
||||
statisticsCreated = savedProgress.statisticsCreated;
|
||||
skipped = savedProgress.skipped;
|
||||
totalResumesProcessed = savedProgress.totalResumesProcessed;
|
||||
errors = savedProgress.errors;
|
||||
}
|
||||
// Load saved progress if exists
|
||||
const savedProgress = await loadProgress();
|
||||
if (savedProgress) {
|
||||
lastSeenCreatedAt = savedProgress.lastSeenCreatedAt;
|
||||
lastSeenId = savedProgress.lastSeenId;
|
||||
resumesCreated = savedProgress.resumesCreated;
|
||||
statisticsCreated = savedProgress.statisticsCreated;
|
||||
skipped = savedProgress.skipped;
|
||||
totalResumesProcessed = savedProgress.totalResumesProcessed;
|
||||
errors = savedProgress.errors;
|
||||
}
|
||||
|
||||
// Helper to get current progress object
|
||||
const getCurrentProgress = (): MigrationProgress => ({
|
||||
lastSeenCreatedAt,
|
||||
lastSeenId,
|
||||
resumesCreated,
|
||||
statisticsCreated,
|
||||
skipped,
|
||||
totalResumesProcessed,
|
||||
errors,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
});
|
||||
// Helper to get current progress object
|
||||
const getCurrentProgress = (): MigrationProgress => ({
|
||||
lastSeenCreatedAt,
|
||||
lastSeenId,
|
||||
resumesCreated,
|
||||
statisticsCreated,
|
||||
skipped,
|
||||
totalResumesProcessed,
|
||||
errors,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
});
|
||||
|
||||
// Setup graceful shutdown handler
|
||||
const handleShutdown = async () => {
|
||||
if (shutdownRequested) return;
|
||||
shutdownRequested = true;
|
||||
console.log("\n⚠️ Shutdown requested. Saving progress...");
|
||||
await saveProgress(getCurrentProgress());
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
console.log("👋 Exiting. Run the script again to resume from where you left off.");
|
||||
process.exit(0);
|
||||
};
|
||||
// Setup graceful shutdown handler
|
||||
const handleShutdown = async () => {
|
||||
if (shutdownRequested) return;
|
||||
shutdownRequested = true;
|
||||
console.log("\n⚠️ Shutdown requested. Saving progress...");
|
||||
await saveProgress(getCurrentProgress());
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
console.log("👋 Exiting. Run the script again to resume from where you left off.");
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on("SIGINT", handleShutdown);
|
||||
process.on("SIGTERM", handleShutdown);
|
||||
process.on("SIGINT", handleShutdown);
|
||||
process.on("SIGTERM", handleShutdown);
|
||||
|
||||
// Initialize the importer
|
||||
const importer = new ReactiveResumeV4JSONImporter();
|
||||
// Initialize the importer
|
||||
const importer = new ReactiveResumeV4JSONImporter();
|
||||
|
||||
while (hasMore) {
|
||||
// Check if shutdown was requested
|
||||
if (shutdownRequested) break;
|
||||
while (hasMore) {
|
||||
// Check if shutdown was requested
|
||||
if (shutdownRequested) break;
|
||||
|
||||
console.log(
|
||||
`📥 Fetching resumes batch from production database (cursor: createdAt=${lastSeenCreatedAt}, id=${lastSeenId})...`,
|
||||
);
|
||||
console.log(
|
||||
`📥 Fetching resumes batch from production database (cursor: createdAt=${lastSeenCreatedAt}, id=${lastSeenId})...`,
|
||||
);
|
||||
|
||||
// Use cursor-based pagination for better performance
|
||||
// Tuple comparison syntax allows Postgres to use composite index efficiently
|
||||
let resumes: ProductionResume[];
|
||||
// Use cursor-based pagination for better performance
|
||||
// Tuple comparison syntax allows Postgres to use composite index efficiently
|
||||
let resumes: ProductionResume[];
|
||||
|
||||
if (lastSeenCreatedAt && lastSeenId) {
|
||||
const result = (await productionDb.execute(sql`
|
||||
if (lastSeenCreatedAt && lastSeenId) {
|
||||
const result = (await productionDb.execute(sql`
|
||||
SELECT id, title, slug, data, visibility, locked, "userId", "createdAt", "updatedAt"
|
||||
FROM "Resume"
|
||||
WHERE ("createdAt", id) < (${lastSeenCreatedAt}::timestamp, ${lastSeenId})
|
||||
ORDER BY "createdAt" DESC, id DESC
|
||||
LIMIT ${BATCH_SIZE}
|
||||
`)) as unknown as QueryResult<ProductionResume>;
|
||||
resumes = result.rows;
|
||||
} else {
|
||||
const result = (await productionDb.execute(sql`
|
||||
resumes = result.rows;
|
||||
} else {
|
||||
const result = (await productionDb.execute(sql`
|
||||
SELECT id, title, slug, data, visibility, locked, "userId", "createdAt", "updatedAt"
|
||||
FROM "Resume"
|
||||
ORDER BY "createdAt" DESC, id DESC
|
||||
LIMIT ${BATCH_SIZE}
|
||||
`)) as unknown as QueryResult<ProductionResume>;
|
||||
resumes = result.rows;
|
||||
}
|
||||
resumes = result.rows;
|
||||
}
|
||||
|
||||
console.log(`📋 Found ${resumes.length} resumes in this batch.`);
|
||||
console.log(`📋 Found ${resumes.length} resumes in this batch.`);
|
||||
|
||||
if (resumes.length === 0) {
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
if (resumes.length === 0) {
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fetch statistics only for these resumes in this batch
|
||||
const resumeIds = resumes.map((r) => r.id);
|
||||
// Fetch statistics only for these resumes in this batch
|
||||
const resumeIds = resumes.map((r) => r.id);
|
||||
|
||||
// Drizzle does not interpolate arrays, so we join and use a custom SQL string
|
||||
// Escape single quotes in IDs (though UUIDs shouldn't contain them, this is safer)
|
||||
const resumeIdsForSql = resumeIds.map((id) => `'${id.replace(/'/g, "''")}'`).join(", ");
|
||||
// Drizzle does not interpolate arrays, so we join and use a custom SQL string
|
||||
// Escape single quotes in IDs (though UUIDs shouldn't contain them, this is safer)
|
||||
const resumeIdsForSql = resumeIds.map((id) => `'${id.replace(/'/g, "''")}'`).join(", ");
|
||||
|
||||
const { rows: statistics } = (await productionDb.execute(sql`
|
||||
const { rows: statistics } = (await productionDb.execute(sql`
|
||||
SELECT id, views, downloads, "resumeId", "createdAt", "updatedAt"
|
||||
FROM "Statistics"
|
||||
WHERE "resumeId" IN (${sql.raw(resumeIdsForSql)})
|
||||
`)) as unknown as QueryResult<ProductionStatistics>;
|
||||
|
||||
// Create a map of resumeId -> statistics for quick lookup
|
||||
const statisticsMap = new Map<string, ProductionStatistics>();
|
||||
for (const stat of statistics) {
|
||||
statisticsMap.set(stat.resumeId, stat);
|
||||
}
|
||||
// Create a map of resumeId -> statistics for quick lookup
|
||||
const statisticsMap = new Map<string, ProductionStatistics>();
|
||||
for (const stat of statistics) {
|
||||
statisticsMap.set(stat.resumeId, stat);
|
||||
}
|
||||
|
||||
// Filter out resumes where userId is not in userIdMap
|
||||
const resumesToProcess = resumes
|
||||
.map((resume) => {
|
||||
const newUserId = userIdMap.get(resume.userId);
|
||||
if (!newUserId) {
|
||||
skipped++;
|
||||
return null;
|
||||
}
|
||||
return { resume, newUserId };
|
||||
})
|
||||
.filter((item): item is NonNullable<typeof item> => item !== null);
|
||||
// Filter out resumes where userId is not in userIdMap
|
||||
const resumesToProcess = resumes
|
||||
.map((resume) => {
|
||||
const newUserId = userIdMap.get(resume.userId);
|
||||
if (!newUserId) {
|
||||
skipped++;
|
||||
return null;
|
||||
}
|
||||
return { resume, newUserId };
|
||||
})
|
||||
.filter((item): item is NonNullable<typeof item> => item !== null);
|
||||
|
||||
if (resumesToProcess.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch have userIds not found in userIdMap.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
if (resumesToProcess.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch have userIds not found in userIdMap.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get unique userIds and bulk check if they exist in local database
|
||||
const uniqueUserIds = [...new Set(resumesToProcess.map((r) => r.newUserId))];
|
||||
const existingUsers = await localDb.select().from(schema.user).where(inArray(schema.user.id, uniqueUserIds));
|
||||
// Get unique userIds and bulk check if they exist in local database
|
||||
const uniqueUserIds = [...new Set(resumesToProcess.map((r) => r.newUserId))];
|
||||
const existingUsers = await localDb.select().from(schema.user).where(inArray(schema.user.id, uniqueUserIds));
|
||||
|
||||
const existingUserIds = new Set(existingUsers.map((u) => u.id));
|
||||
const existingUserIds = new Set(existingUsers.map((u) => u.id));
|
||||
|
||||
// Filter out resumes where user doesn't exist
|
||||
const resumesWithValidUsers = resumesToProcess.filter(({ newUserId }) => {
|
||||
if (!existingUserIds.has(newUserId)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Filter out resumes where user doesn't exist
|
||||
const resumesWithValidUsers = resumesToProcess.filter(({ newUserId }) => {
|
||||
if (!existingUserIds.has(newUserId)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (resumesWithValidUsers.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch have userIds not found in local database.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
if (resumesWithValidUsers.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch have userIds not found in local database.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bulk check for existing resumes (by slug + userId)
|
||||
// We need to check each unique combination
|
||||
const slugUserIdPairs = resumesWithValidUsers.map(({ resume, newUserId }) => ({
|
||||
slug: resume.slug,
|
||||
userId: newUserId,
|
||||
}));
|
||||
// Bulk check for existing resumes (by slug + userId)
|
||||
// We need to check each unique combination
|
||||
const slugUserIdPairs = resumesWithValidUsers.map(({ resume, newUserId }) => ({
|
||||
slug: resume.slug,
|
||||
userId: newUserId,
|
||||
}));
|
||||
|
||||
// Get all unique slugs and userIds
|
||||
const uniqueSlugs = [...new Set(slugUserIdPairs.map((p) => p.slug))];
|
||||
const userIdsForSlugCheck = [...new Set(slugUserIdPairs.map((p) => p.userId))];
|
||||
// Get all unique slugs and userIds
|
||||
const uniqueSlugs = [...new Set(slugUserIdPairs.map((p) => p.slug))];
|
||||
const userIdsForSlugCheck = [...new Set(slugUserIdPairs.map((p) => p.userId))];
|
||||
|
||||
// Fetch all existing resumes that match any of our slugs and userIds
|
||||
const existingResumes = await localDb
|
||||
.select()
|
||||
.from(schema.resume)
|
||||
.where(and(inArray(schema.resume.slug, uniqueSlugs), inArray(schema.resume.userId, userIdsForSlugCheck)));
|
||||
// Fetch all existing resumes that match any of our slugs and userIds
|
||||
const existingResumes = await localDb
|
||||
.select()
|
||||
.from(schema.resume)
|
||||
.where(and(inArray(schema.resume.slug, uniqueSlugs), inArray(schema.resume.userId, userIdsForSlugCheck)));
|
||||
|
||||
// Create a set of existing slug+userId combinations
|
||||
const existingResumeKeys = new Set(existingResumes.map((r) => `${r.slug}:${r.userId}`));
|
||||
// Create a set of existing slug+userId combinations
|
||||
const existingResumeKeys = new Set(existingResumes.map((r) => `${r.slug}:${r.userId}`));
|
||||
|
||||
// Filter out resumes that already exist
|
||||
const resumesToInsert = resumesWithValidUsers.filter(({ resume, newUserId }) => {
|
||||
const key = `${resume.slug}:${newUserId}`;
|
||||
if (existingResumeKeys.has(key)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Filter out resumes that already exist
|
||||
const resumesToInsert = resumesWithValidUsers.filter(({ resume, newUserId }) => {
|
||||
const key = `${resume.slug}:${newUserId}`;
|
||||
if (existingResumeKeys.has(key)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (resumesToInsert.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch already exist in target DB.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
if (resumesToInsert.length === 0) {
|
||||
console.log(`⏭️ All resumes in this batch already exist in target DB.`);
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
totalResumesProcessed += resumes.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`📝 Preparing to bulk insert ${resumesToInsert.length} resumes...`);
|
||||
console.log(`📝 Preparing to bulk insert ${resumesToInsert.length} resumes...`);
|
||||
|
||||
// Prepare bulk insert data
|
||||
const batchStart = performance.now();
|
||||
try {
|
||||
const resumesToInsertData = resumesToInsert.map(({ resume, newUserId }) => {
|
||||
// Transform the data using the V4 importer
|
||||
let transformedData = defaultResumeData;
|
||||
try {
|
||||
const dataJson = typeof resume.data === "string" ? resume.data : JSON.stringify(resume.data);
|
||||
transformedData = importer.parse(dataJson);
|
||||
} catch (error) {
|
||||
console.error(`⚠️ Failed to parse resume data for resume ${resume.id}, using default data:`, error);
|
||||
// Use default data if parsing fails
|
||||
transformedData = defaultResumeData;
|
||||
}
|
||||
// Prepare bulk insert data
|
||||
const batchStart = performance.now();
|
||||
try {
|
||||
const resumesToInsertData = resumesToInsert.map(({ resume, newUserId }) => {
|
||||
// Transform the data using the V4 importer
|
||||
let transformedData = defaultResumeData;
|
||||
try {
|
||||
const dataJson = typeof resume.data === "string" ? resume.data : JSON.stringify(resume.data);
|
||||
transformedData = importer.parse(dataJson);
|
||||
} catch (error) {
|
||||
console.error(`⚠️ Failed to parse resume data for resume ${resume.id}, using default data:`, error);
|
||||
// Use default data if parsing fails
|
||||
transformedData = defaultResumeData;
|
||||
}
|
||||
|
||||
// Map visibility to isPublic (visibility === "public" -> isPublic = true)
|
||||
const isPublic = resume.visibility === "public";
|
||||
// Map visibility to isPublic (visibility === "public" -> isPublic = true)
|
||||
const isPublic = resume.visibility === "public";
|
||||
|
||||
const newResumeId = generateId();
|
||||
const newResumeId = generateId();
|
||||
|
||||
// Track the ID mapping for future reference
|
||||
resumeIdMap.set(resume.id, newResumeId);
|
||||
// Track the ID mapping for future reference
|
||||
resumeIdMap.set(resume.id, newResumeId);
|
||||
|
||||
return {
|
||||
resumeData: {
|
||||
id: newResumeId,
|
||||
name: resume.title,
|
||||
slug: resume.slug,
|
||||
tags: [], // Default empty array
|
||||
isPublic: isPublic,
|
||||
isLocked: resume.locked,
|
||||
password: null, // No password in old schema
|
||||
data: transformedData,
|
||||
userId: newUserId,
|
||||
createdAt: resume.createdAt,
|
||||
updatedAt: resume.updatedAt,
|
||||
},
|
||||
originalResumeId: resume.id,
|
||||
newResumeId: newResumeId,
|
||||
};
|
||||
});
|
||||
return {
|
||||
resumeData: {
|
||||
id: newResumeId,
|
||||
name: resume.title,
|
||||
slug: resume.slug,
|
||||
tags: [], // Default empty array
|
||||
isPublic: isPublic,
|
||||
isLocked: resume.locked,
|
||||
password: null, // No password in old schema
|
||||
data: transformedData,
|
||||
userId: newUserId,
|
||||
createdAt: resume.createdAt,
|
||||
updatedAt: resume.updatedAt,
|
||||
},
|
||||
originalResumeId: resume.id,
|
||||
newResumeId: newResumeId,
|
||||
};
|
||||
});
|
||||
|
||||
// Bulk insert resumes (chunked to avoid PostgreSQL message size limits)
|
||||
// Resumes contain large JSONB data, so we use smaller chunks
|
||||
const resumeDataList = resumesToInsertData.map(({ resumeData }) => resumeData);
|
||||
for (let i = 0; i < resumeDataList.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = resumeDataList.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.resume).values(chunk);
|
||||
}
|
||||
resumesCreated += resumesToInsertData.length;
|
||||
// Bulk insert resumes (chunked to avoid PostgreSQL message size limits)
|
||||
// Resumes contain large JSONB data, so we use smaller chunks
|
||||
const resumeDataList = resumesToInsertData.map(({ resumeData }) => resumeData);
|
||||
for (let i = 0; i < resumeDataList.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = resumeDataList.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.resume).values(chunk);
|
||||
}
|
||||
resumesCreated += resumesToInsertData.length;
|
||||
|
||||
// Prepare statistics for bulk insert
|
||||
const statisticsToInsert = resumesToInsertData
|
||||
.map(({ originalResumeId, newResumeId }) => {
|
||||
const resumeStatistics = statisticsMap.get(originalResumeId);
|
||||
if (!resumeStatistics) return null;
|
||||
// Prepare statistics for bulk insert
|
||||
const statisticsToInsert = resumesToInsertData
|
||||
.map(({ originalResumeId, newResumeId }) => {
|
||||
const resumeStatistics = statisticsMap.get(originalResumeId);
|
||||
if (!resumeStatistics) return null;
|
||||
|
||||
return {
|
||||
id: generateId(),
|
||||
views: resumeStatistics.views,
|
||||
downloads: resumeStatistics.downloads,
|
||||
lastViewedAt: null, // Not available in old schema
|
||||
lastDownloadedAt: null, // Not available in old schema
|
||||
resumeId: newResumeId,
|
||||
createdAt: resumeStatistics.createdAt,
|
||||
updatedAt: resumeStatistics.updatedAt,
|
||||
};
|
||||
})
|
||||
.filter((stat): stat is NonNullable<typeof stat> => stat !== null);
|
||||
return {
|
||||
id: generateId(),
|
||||
views: resumeStatistics.views,
|
||||
downloads: resumeStatistics.downloads,
|
||||
lastViewedAt: null, // Not available in old schema
|
||||
lastDownloadedAt: null, // Not available in old schema
|
||||
resumeId: newResumeId,
|
||||
createdAt: resumeStatistics.createdAt,
|
||||
updatedAt: resumeStatistics.updatedAt,
|
||||
};
|
||||
})
|
||||
.filter((stat): stat is NonNullable<typeof stat> => stat !== null);
|
||||
|
||||
// Bulk insert statistics (chunked)
|
||||
if (statisticsToInsert.length > 0) {
|
||||
for (let i = 0; i < statisticsToInsert.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = statisticsToInsert.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.resumeStatistics).values(chunk);
|
||||
}
|
||||
statisticsCreated += statisticsToInsert.length;
|
||||
}
|
||||
// Bulk insert statistics (chunked)
|
||||
if (statisticsToInsert.length > 0) {
|
||||
for (let i = 0; i < statisticsToInsert.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = statisticsToInsert.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.resumeStatistics).values(chunk);
|
||||
}
|
||||
statisticsCreated += statisticsToInsert.length;
|
||||
}
|
||||
|
||||
const batchEnd = performance.now();
|
||||
const batchTimeMs = batchEnd - batchStart;
|
||||
console.log(
|
||||
`✅ Bulk inserted ${resumesToInsertData.length} resumes in ${batchTimeMs.toFixed(1)} ms (avg ${(batchTimeMs / resumesToInsertData.length).toFixed(1)} ms/resume)`,
|
||||
);
|
||||
const batchEnd = performance.now();
|
||||
const batchTimeMs = batchEnd - batchStart;
|
||||
console.log(
|
||||
`✅ Bulk inserted ${resumesToInsertData.length} resumes in ${batchTimeMs.toFixed(1)} ms (avg ${(batchTimeMs / resumesToInsertData.length).toFixed(1)} ms/resume)`,
|
||||
);
|
||||
|
||||
// Save resume ID map after each successful batch
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
} catch (error) {
|
||||
console.error(`🚨 Failed to bulk insert resumes batch:`, error);
|
||||
errors++;
|
||||
// Continue with next batch even if this one fails
|
||||
}
|
||||
// Save resume ID map after each successful batch
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
} catch (error) {
|
||||
console.error(`🚨 Failed to bulk insert resumes batch:`, error);
|
||||
errors++;
|
||||
// Continue with next batch even if this one fails
|
||||
}
|
||||
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
// Update cursor to the last resume in this batch
|
||||
const lastResume = resumes[resumes.length - 1];
|
||||
if (lastResume) {
|
||||
lastSeenCreatedAt =
|
||||
lastResume.createdAt instanceof Date ? lastResume.createdAt.toISOString() : String(lastResume.createdAt);
|
||||
lastSeenId = lastResume.id;
|
||||
}
|
||||
|
||||
totalResumesProcessed += resumes.length;
|
||||
console.log(`📦 Processed ${totalResumesProcessed} resumes so far...\n`);
|
||||
totalResumesProcessed += resumes.length;
|
||||
console.log(`📦 Processed ${totalResumesProcessed} resumes so far...\n`);
|
||||
|
||||
// Save progress after each batch
|
||||
await saveProgress(getCurrentProgress());
|
||||
}
|
||||
// Save progress after each batch
|
||||
await saveProgress(getCurrentProgress());
|
||||
}
|
||||
|
||||
// Remove signal handlers
|
||||
process.off("SIGINT", handleShutdown);
|
||||
process.off("SIGTERM", handleShutdown);
|
||||
// Remove signal handlers
|
||||
process.off("SIGINT", handleShutdown);
|
||||
process.off("SIGTERM", handleShutdown);
|
||||
|
||||
const migrationEnd = performance.now();
|
||||
const migrationDurationMs = migrationEnd - migrationStart;
|
||||
const migrationEnd = performance.now();
|
||||
const migrationDurationMs = migrationEnd - migrationStart;
|
||||
|
||||
console.log("\n📊 Migration Summary:");
|
||||
console.log(` Resumes created: ${resumesCreated}`);
|
||||
console.log(` Statistics created: ${statisticsCreated}`);
|
||||
console.log(` Skipped (userId not found or already exist): ${skipped}`);
|
||||
console.log(` Errors: ${errors}`);
|
||||
console.log(
|
||||
`⏱️ Total migration time: ${migrationDurationMs.toFixed(1)} ms (${(migrationDurationMs / 1000).toFixed(2)} seconds)`,
|
||||
);
|
||||
console.log("\n📊 Migration Summary:");
|
||||
console.log(` Resumes created: ${resumesCreated}`);
|
||||
console.log(` Statistics created: ${statisticsCreated}`);
|
||||
console.log(` Skipped (userId not found or already exist): ${skipped}`);
|
||||
console.log(` Errors: ${errors}`);
|
||||
console.log(
|
||||
`⏱️ Total migration time: ${migrationDurationMs.toFixed(1)} ms (${(migrationDurationMs / 1000).toFixed(2)} seconds)`,
|
||||
);
|
||||
|
||||
// Final save of the mapping (ensures up-to-date state)
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
// Final save of the mapping (ensures up-to-date state)
|
||||
await saveResumeIdMapToFile(resumeIdMap);
|
||||
|
||||
// Clear progress file on successful completion (only if not interrupted)
|
||||
if (!shutdownRequested) {
|
||||
await clearProgress();
|
||||
console.log("✅ Resume migration complete!");
|
||||
} else {
|
||||
console.log("⏸️ Migration paused. Run again to resume.");
|
||||
}
|
||||
// Clear progress file on successful completion (only if not interrupted)
|
||||
if (!shutdownRequested) {
|
||||
await clearProgress();
|
||||
console.log("✅ Resume migration complete!");
|
||||
} else {
|
||||
console.log("⏸️ Migration paused. Run again to resume.");
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
// Reset shutdown flag for fresh run
|
||||
shutdownRequested = false;
|
||||
// Reset shutdown flag for fresh run
|
||||
shutdownRequested = false;
|
||||
|
||||
try {
|
||||
await migrateResumes();
|
||||
} finally {
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
}
|
||||
try {
|
||||
await migrateResumes();
|
||||
} finally {
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@ const localPool = new Pool({ connectionString: localUrl });
|
||||
const localDb = drizzle({ client: localPool });
|
||||
|
||||
try {
|
||||
const productionResult = await productionDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Production database connection successful", JSON.stringify(productionResult));
|
||||
const productionResult = await productionDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Production database connection successful", JSON.stringify(productionResult));
|
||||
|
||||
const localResult = await localDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Local database connection successful", JSON.stringify(localResult));
|
||||
const localResult = await localDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Local database connection successful", JSON.stringify(localResult));
|
||||
} catch (error) {
|
||||
console.error("🚨 Database connection failed:", error);
|
||||
process.exit(1);
|
||||
console.error("🚨 Database connection failed:", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
process.exit(0);
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
+317
-317
@@ -12,37 +12,37 @@ type Provider = "credential" | "google" | "github" | "custom";
|
||||
type ProductionProvider = "email" | "github" | "google" | "openid";
|
||||
|
||||
interface ProductionUser {
|
||||
id: string;
|
||||
name: string;
|
||||
picture: string | null;
|
||||
username: string;
|
||||
email: string;
|
||||
locale: string;
|
||||
emailVerified: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
provider: ProductionProvider;
|
||||
id: string;
|
||||
name: string;
|
||||
picture: string | null;
|
||||
username: string;
|
||||
email: string;
|
||||
locale: string;
|
||||
emailVerified: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
provider: ProductionProvider;
|
||||
}
|
||||
|
||||
interface ProductionSecrets {
|
||||
id: string;
|
||||
password: string | null;
|
||||
lastSignedIn: Date;
|
||||
userId: string;
|
||||
id: string;
|
||||
password: string | null;
|
||||
lastSignedIn: Date;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
// Map old provider to new providerId
|
||||
function mapProviderId(provider: ProductionProvider): Provider {
|
||||
switch (provider) {
|
||||
case "email":
|
||||
return "credential";
|
||||
case "google":
|
||||
return "google";
|
||||
case "github":
|
||||
return "github";
|
||||
default:
|
||||
return "custom";
|
||||
}
|
||||
switch (provider) {
|
||||
case "email":
|
||||
return "credential";
|
||||
case "google":
|
||||
return "google";
|
||||
case "github":
|
||||
return "github";
|
||||
default:
|
||||
return "custom";
|
||||
}
|
||||
}
|
||||
|
||||
const productionUrl = process.env.PRODUCTION_DATABASE_URL;
|
||||
@@ -72,380 +72,380 @@ const INSERT_CHUNK_SIZE = 1000;
|
||||
// == Progress checkpoint interface ==
|
||||
// Uses cursor-based pagination with (createdAt, id) composite key for efficiency
|
||||
interface MigrationProgress {
|
||||
// Cursor for pagination - last seen createdAt timestamp
|
||||
lastSeenCreatedAt: string | null;
|
||||
// Cursor for pagination - last seen id (for tiebreaker when timestamps are equal)
|
||||
lastSeenId: string | null;
|
||||
usersCreated: number;
|
||||
accountsCreated: number;
|
||||
skipped: number;
|
||||
totalUsersProcessed: number;
|
||||
lastUpdated: string;
|
||||
// Cursor for pagination - last seen createdAt timestamp
|
||||
lastSeenCreatedAt: string | null;
|
||||
// Cursor for pagination - last seen id (for tiebreaker when timestamps are equal)
|
||||
lastSeenId: string | null;
|
||||
usersCreated: number;
|
||||
accountsCreated: number;
|
||||
skipped: number;
|
||||
totalUsersProcessed: number;
|
||||
lastUpdated: string;
|
||||
}
|
||||
|
||||
// Flag to track if shutdown was requested
|
||||
let shutdownRequested = false;
|
||||
|
||||
async function loadProgress(): Promise<MigrationProgress | null> {
|
||||
try {
|
||||
const text = await fs.readFile(PROGRESS_FILE, { encoding: "utf-8" });
|
||||
const progress = JSON.parse(text) as MigrationProgress;
|
||||
console.log(`📂 Found existing progress file. Last updated: ${progress.lastUpdated}`);
|
||||
console.log(` Resuming from cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})...`);
|
||||
return progress;
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load progress file, starting from beginning.", e);
|
||||
}
|
||||
return null;
|
||||
try {
|
||||
const text = await fs.readFile(PROGRESS_FILE, { encoding: "utf-8" });
|
||||
const progress = JSON.parse(text) as MigrationProgress;
|
||||
console.log(`📂 Found existing progress file. Last updated: ${progress.lastUpdated}`);
|
||||
console.log(` Resuming from cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})...`);
|
||||
return progress;
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load progress file, starting from beginning.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function saveProgress(progress: MigrationProgress): Promise<void> {
|
||||
try {
|
||||
progress.lastUpdated = new Date().toISOString();
|
||||
await fs.writeFile(PROGRESS_FILE, JSON.stringify(progress, null, 2), { encoding: "utf-8" });
|
||||
console.log(`💾 Progress saved at cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})`);
|
||||
} catch (e) {
|
||||
console.error("🚨 Failed to save progress:", e);
|
||||
}
|
||||
try {
|
||||
progress.lastUpdated = new Date().toISOString();
|
||||
await fs.writeFile(PROGRESS_FILE, JSON.stringify(progress, null, 2), { encoding: "utf-8" });
|
||||
console.log(`💾 Progress saved at cursor (createdAt: ${progress.lastSeenCreatedAt}, id: ${progress.lastSeenId})`);
|
||||
} catch (e) {
|
||||
console.error("🚨 Failed to save progress:", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function clearProgress(): Promise<void> {
|
||||
try {
|
||||
await fs.unlink(PROGRESS_FILE);
|
||||
console.log("🗑️ Progress file cleared.");
|
||||
} catch {
|
||||
// Ignore errors when clearing
|
||||
}
|
||||
try {
|
||||
await fs.unlink(PROGRESS_FILE);
|
||||
console.log("🗑️ Progress file cleared.");
|
||||
} catch {
|
||||
// Ignore errors when clearing
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUserIdMapFromFile(): Promise<Map<string, string>> {
|
||||
try {
|
||||
const text = await fs.readFile(USER_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load userIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
try {
|
||||
const text = await fs.readFile(USER_ID_MAP_FILE, { encoding: "utf-8" });
|
||||
const obj = JSON.parse(text);
|
||||
return new Map(Object.entries(obj));
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Failed to load userIdMap from disk, continuing with empty map.", e);
|
||||
}
|
||||
return new Map<string, string>();
|
||||
}
|
||||
|
||||
async function saveUserIdMapToFile(userIdMap: Map<string, string>) {
|
||||
const obj: Record<string, string> = Object.fromEntries(userIdMap.entries());
|
||||
await fs.writeFile(USER_ID_MAP_FILE, JSON.stringify(obj, null, "\t"), { encoding: "utf-8" });
|
||||
const obj: Record<string, string> = Object.fromEntries(userIdMap.entries());
|
||||
await fs.writeFile(USER_ID_MAP_FILE, JSON.stringify(obj, null, "\t"), { encoding: "utf-8" });
|
||||
}
|
||||
|
||||
export async function migrateUsers() {
|
||||
const migrationStart = performance.now();
|
||||
console.log("⌛ Starting user migration...");
|
||||
const migrationStart = performance.now();
|
||||
console.log("⌛ Starting user migration...");
|
||||
|
||||
let hasMore = true;
|
||||
let hasMore = true;
|
||||
|
||||
// Cursor-based pagination state
|
||||
let lastSeenCreatedAt: string | null = null;
|
||||
let lastSeenId: string | null = null;
|
||||
// Cursor-based pagination state
|
||||
let lastSeenCreatedAt: string | null = null;
|
||||
let lastSeenId: string | null = null;
|
||||
|
||||
// Load persistent userIdMap from file
|
||||
const userIdMap = await loadUserIdMapFromFile();
|
||||
// Load persistent userIdMap from file
|
||||
const userIdMap = await loadUserIdMapFromFile();
|
||||
|
||||
// Track migration stats
|
||||
let usersCreated = 0;
|
||||
let accountsCreated = 0;
|
||||
let skipped = 0;
|
||||
let totalUsersProcessed = 0;
|
||||
// Track migration stats
|
||||
let usersCreated = 0;
|
||||
let accountsCreated = 0;
|
||||
let skipped = 0;
|
||||
let totalUsersProcessed = 0;
|
||||
|
||||
// Load saved progress if exists
|
||||
const savedProgress = await loadProgress();
|
||||
if (savedProgress) {
|
||||
lastSeenCreatedAt = savedProgress.lastSeenCreatedAt;
|
||||
lastSeenId = savedProgress.lastSeenId;
|
||||
usersCreated = savedProgress.usersCreated;
|
||||
accountsCreated = savedProgress.accountsCreated;
|
||||
skipped = savedProgress.skipped;
|
||||
totalUsersProcessed = savedProgress.totalUsersProcessed;
|
||||
}
|
||||
// Load saved progress if exists
|
||||
const savedProgress = await loadProgress();
|
||||
if (savedProgress) {
|
||||
lastSeenCreatedAt = savedProgress.lastSeenCreatedAt;
|
||||
lastSeenId = savedProgress.lastSeenId;
|
||||
usersCreated = savedProgress.usersCreated;
|
||||
accountsCreated = savedProgress.accountsCreated;
|
||||
skipped = savedProgress.skipped;
|
||||
totalUsersProcessed = savedProgress.totalUsersProcessed;
|
||||
}
|
||||
|
||||
// Helper to get current progress object
|
||||
const getCurrentProgress = (): MigrationProgress => ({
|
||||
lastSeenCreatedAt,
|
||||
lastSeenId,
|
||||
usersCreated,
|
||||
accountsCreated,
|
||||
skipped,
|
||||
totalUsersProcessed,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
});
|
||||
// Helper to get current progress object
|
||||
const getCurrentProgress = (): MigrationProgress => ({
|
||||
lastSeenCreatedAt,
|
||||
lastSeenId,
|
||||
usersCreated,
|
||||
accountsCreated,
|
||||
skipped,
|
||||
totalUsersProcessed,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
});
|
||||
|
||||
// Setup graceful shutdown handler
|
||||
const handleShutdown = async () => {
|
||||
if (shutdownRequested) return;
|
||||
shutdownRequested = true;
|
||||
console.log("\n⚠️ Shutdown requested. Saving progress...");
|
||||
await saveProgress(getCurrentProgress());
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
console.log("👋 Exiting. Run the script again to resume from where you left off.");
|
||||
process.exit(0);
|
||||
};
|
||||
// Setup graceful shutdown handler
|
||||
const handleShutdown = async () => {
|
||||
if (shutdownRequested) return;
|
||||
shutdownRequested = true;
|
||||
console.log("\n⚠️ Shutdown requested. Saving progress...");
|
||||
await saveProgress(getCurrentProgress());
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
console.log("👋 Exiting. Run the script again to resume from where you left off.");
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on("SIGINT", handleShutdown);
|
||||
process.on("SIGTERM", handleShutdown);
|
||||
process.on("SIGINT", handleShutdown);
|
||||
process.on("SIGTERM", handleShutdown);
|
||||
|
||||
while (hasMore) {
|
||||
// Check if shutdown was requested
|
||||
if (shutdownRequested) break;
|
||||
while (hasMore) {
|
||||
// Check if shutdown was requested
|
||||
if (shutdownRequested) break;
|
||||
|
||||
console.log(
|
||||
`📥 Fetching users batch from production database (cursor: createdAt=${lastSeenCreatedAt}, id=${lastSeenId})...`,
|
||||
);
|
||||
console.log(
|
||||
`📥 Fetching users batch from production database (cursor: createdAt=${lastSeenCreatedAt}, id=${lastSeenId})...`,
|
||||
);
|
||||
|
||||
let users: ProductionUser[];
|
||||
let users: ProductionUser[];
|
||||
|
||||
if (lastSeenCreatedAt && lastSeenId) {
|
||||
const result = (await productionDb.execute(sql`
|
||||
if (lastSeenCreatedAt && lastSeenId) {
|
||||
const result = (await productionDb.execute(sql`
|
||||
SELECT id, name, picture, username, email, locale, "emailVerified", "createdAt", "updatedAt", provider
|
||||
FROM "User"
|
||||
WHERE ("createdAt", id) < (${lastSeenCreatedAt}::timestamp, ${lastSeenId})
|
||||
ORDER BY "createdAt" DESC, id DESC
|
||||
LIMIT ${BATCH_SIZE}
|
||||
`)) as unknown as QueryResult<ProductionUser>;
|
||||
users = result.rows;
|
||||
} else {
|
||||
const result = (await productionDb.execute(sql`
|
||||
users = result.rows;
|
||||
} else {
|
||||
const result = (await productionDb.execute(sql`
|
||||
SELECT id, name, picture, username, email, locale, "emailVerified", "createdAt", "updatedAt", provider
|
||||
FROM "User"
|
||||
ORDER BY "createdAt" DESC, id DESC
|
||||
LIMIT ${BATCH_SIZE}
|
||||
`)) as unknown as QueryResult<ProductionUser>;
|
||||
users = result.rows;
|
||||
}
|
||||
users = result.rows;
|
||||
}
|
||||
|
||||
console.log(`📋 Found ${users.length} users in this batch.`);
|
||||
console.log(`📋 Found ${users.length} users in this batch.`);
|
||||
|
||||
if (users.length === 0) {
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
if (users.length === 0) {
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fetch secrets only for these users in this batch
|
||||
const userIds = users.map((u) => u.id);
|
||||
// Fetch secrets only for these users in this batch
|
||||
const userIds = users.map((u) => u.id);
|
||||
|
||||
// Drizzle does not interpolate arrays, so we join and use a custom SQL string
|
||||
// Escape single quotes in IDs (though UUIDs shouldn't contain them, this is safer)
|
||||
const userIdsForSql = userIds.map((id) => `'${id.replace(/'/g, "''")}'`).join(", ");
|
||||
// Drizzle does not interpolate arrays, so we join and use a custom SQL string
|
||||
// Escape single quotes in IDs (though UUIDs shouldn't contain them, this is safer)
|
||||
const userIdsForSql = userIds.map((id) => `'${id.replace(/'/g, "''")}'`).join(", ");
|
||||
|
||||
const { rows: secrets } = (await productionDb.execute(sql`
|
||||
const { rows: secrets } = (await productionDb.execute(sql`
|
||||
SELECT id, password, "lastSignedIn", "userId"
|
||||
FROM "Secrets"
|
||||
WHERE "userId" IN (${sql.raw(userIdsForSql)})
|
||||
`)) as unknown as QueryResult<ProductionSecrets>;
|
||||
|
||||
// Create a map of userId -> secrets for quick lookup
|
||||
const secretsMap = new Map<string, ProductionSecrets>();
|
||||
for (const secret of secrets) {
|
||||
secretsMap.set(secret.userId, secret);
|
||||
}
|
||||
// Create a map of userId -> secrets for quick lookup
|
||||
const secretsMap = new Map<string, ProductionSecrets>();
|
||||
for (const secret of secrets) {
|
||||
secretsMap.set(secret.userId, secret);
|
||||
}
|
||||
|
||||
// Filter out users already in userIdMap (previously migrated)
|
||||
const usersToProcess = users.filter((user) => {
|
||||
if (userIdMap.has(user.id)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Filter out users already in userIdMap (previously migrated)
|
||||
const usersToProcess = users.filter((user) => {
|
||||
if (userIdMap.has(user.id)) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (usersToProcess.length === 0) {
|
||||
console.log(`⏭️ All users in this batch were already migrated.`);
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
totalUsersProcessed += users.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
if (usersToProcess.length === 0) {
|
||||
console.log(`⏭️ All users in this batch were already migrated.`);
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
totalUsersProcessed += users.length;
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prepare usernames for all users
|
||||
const userData = usersToProcess.map((user) => ({
|
||||
user,
|
||||
username: toUsername(user.username),
|
||||
displayUsername: user.username,
|
||||
}));
|
||||
// Prepare usernames for all users
|
||||
const userData = usersToProcess.map((user) => ({
|
||||
user,
|
||||
username: toUsername(user.username),
|
||||
displayUsername: user.username,
|
||||
}));
|
||||
|
||||
// Bulk check for existing users (by email or username)
|
||||
const emails = userData.map((u) => u.user.email);
|
||||
const usernames = userData.map((u) => u.username);
|
||||
const displayUsernames = userData.map((u) => u.displayUsername);
|
||||
// Bulk check for existing users (by email or username)
|
||||
const emails = userData.map((u) => u.user.email);
|
||||
const usernames = userData.map((u) => u.username);
|
||||
const displayUsernames = userData.map((u) => u.displayUsername);
|
||||
|
||||
const existingUsers = await localDb
|
||||
.select()
|
||||
.from(schema.user)
|
||||
.where(
|
||||
or(
|
||||
inArray(schema.user.email, emails),
|
||||
inArray(schema.user.username, usernames),
|
||||
inArray(schema.user.displayUsername, displayUsernames),
|
||||
),
|
||||
);
|
||||
const existingUsers = await localDb
|
||||
.select()
|
||||
.from(schema.user)
|
||||
.where(
|
||||
or(
|
||||
inArray(schema.user.email, emails),
|
||||
inArray(schema.user.username, usernames),
|
||||
inArray(schema.user.displayUsername, displayUsernames),
|
||||
),
|
||||
);
|
||||
|
||||
const existingEmails = new Set(existingUsers.map((u) => u.email));
|
||||
const existingUsernames = new Set(existingUsers.map((u) => u.username));
|
||||
const existingDisplayUsernames = new Set(existingUsers.map((u) => u.displayUsername));
|
||||
const existingEmails = new Set(existingUsers.map((u) => u.email));
|
||||
const existingUsernames = new Set(existingUsers.map((u) => u.username));
|
||||
const existingDisplayUsernames = new Set(existingUsers.map((u) => u.displayUsername));
|
||||
|
||||
// Filter out users that already exist
|
||||
const usersToInsert = userData.filter(({ user, username, displayUsername }) => {
|
||||
if (
|
||||
existingEmails.has(user.email) ||
|
||||
existingUsernames.has(username) ||
|
||||
existingDisplayUsernames.has(displayUsername)
|
||||
) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Filter out users that already exist
|
||||
const usersToInsert = userData.filter(({ user, username, displayUsername }) => {
|
||||
if (
|
||||
existingEmails.has(user.email) ||
|
||||
existingUsernames.has(username) ||
|
||||
existingDisplayUsernames.has(displayUsername)
|
||||
) {
|
||||
skipped++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (usersToInsert.length === 0) {
|
||||
console.log(`⏭️ All users in this batch already exist in target DB.`);
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
totalUsersProcessed += users.length;
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
if (usersToInsert.length === 0) {
|
||||
console.log(`⏭️ All users in this batch already exist in target DB.`);
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
totalUsersProcessed += users.length;
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
await saveProgress(getCurrentProgress());
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`📝 Preparing to bulk insert ${usersToInsert.length} users...`);
|
||||
console.log(`📝 Preparing to bulk insert ${usersToInsert.length} users...`);
|
||||
|
||||
// Prepare bulk insert data
|
||||
const usersToInsertData = usersToInsert.map(({ user, username, displayUsername }) => {
|
||||
const newUserId = generateId();
|
||||
userIdMap.set(user.id, newUserId);
|
||||
return {
|
||||
userData: {
|
||||
id: newUserId,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
image: user.picture,
|
||||
username: username,
|
||||
displayUsername: displayUsername,
|
||||
emailVerified: user.emailVerified,
|
||||
twoFactorEnabled: false, // All users start with 2FA disabled in the new system
|
||||
createdAt: user.createdAt,
|
||||
updatedAt: user.updatedAt,
|
||||
},
|
||||
originalUser: user,
|
||||
newUserId: newUserId,
|
||||
};
|
||||
});
|
||||
// Prepare bulk insert data
|
||||
const usersToInsertData = usersToInsert.map(({ user, username, displayUsername }) => {
|
||||
const newUserId = generateId();
|
||||
userIdMap.set(user.id, newUserId);
|
||||
return {
|
||||
userData: {
|
||||
id: newUserId,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
image: user.picture,
|
||||
username: username,
|
||||
displayUsername: displayUsername,
|
||||
emailVerified: user.emailVerified,
|
||||
twoFactorEnabled: false, // All users start with 2FA disabled in the new system
|
||||
createdAt: user.createdAt,
|
||||
updatedAt: user.updatedAt,
|
||||
},
|
||||
originalUser: user,
|
||||
newUserId: newUserId,
|
||||
};
|
||||
});
|
||||
|
||||
// Bulk insert users (chunked to avoid PostgreSQL message size limits)
|
||||
const batchStart = performance.now();
|
||||
try {
|
||||
const userDataList = usersToInsertData.map(({ userData }) => userData);
|
||||
for (let i = 0; i < userDataList.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = userDataList.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.user).values(chunk);
|
||||
}
|
||||
usersCreated += usersToInsertData.length;
|
||||
// Bulk insert users (chunked to avoid PostgreSQL message size limits)
|
||||
const batchStart = performance.now();
|
||||
try {
|
||||
const userDataList = usersToInsertData.map(({ userData }) => userData);
|
||||
for (let i = 0; i < userDataList.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = userDataList.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.user).values(chunk);
|
||||
}
|
||||
usersCreated += usersToInsertData.length;
|
||||
|
||||
// Prepare accounts for bulk insert
|
||||
const accountsToInsert = usersToInsertData.map(({ originalUser, newUserId, userData }) => {
|
||||
const userSecrets = secretsMap.get(originalUser.id);
|
||||
const providerId = mapProviderId(originalUser.provider);
|
||||
const accountId = providerId === "credential" ? newUserId : originalUser.id;
|
||||
// Prepare accounts for bulk insert
|
||||
const accountsToInsert = usersToInsertData.map(({ originalUser, newUserId, userData }) => {
|
||||
const userSecrets = secretsMap.get(originalUser.id);
|
||||
const providerId = mapProviderId(originalUser.provider);
|
||||
const accountId = providerId === "credential" ? newUserId : originalUser.id;
|
||||
|
||||
return {
|
||||
id: generateId(),
|
||||
userId: newUserId,
|
||||
accountId: accountId,
|
||||
providerId: providerId,
|
||||
password: userSecrets?.password ?? null,
|
||||
createdAt: userData.createdAt,
|
||||
updatedAt: userData.updatedAt,
|
||||
};
|
||||
});
|
||||
return {
|
||||
id: generateId(),
|
||||
userId: newUserId,
|
||||
accountId: accountId,
|
||||
providerId: providerId,
|
||||
password: userSecrets?.password ?? null,
|
||||
createdAt: userData.createdAt,
|
||||
updatedAt: userData.updatedAt,
|
||||
};
|
||||
});
|
||||
|
||||
// Bulk insert accounts (chunked)
|
||||
for (let i = 0; i < accountsToInsert.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = accountsToInsert.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.account).values(chunk);
|
||||
}
|
||||
accountsCreated += accountsToInsert.length;
|
||||
// Bulk insert accounts (chunked)
|
||||
for (let i = 0; i < accountsToInsert.length; i += INSERT_CHUNK_SIZE) {
|
||||
const chunk = accountsToInsert.slice(i, i + INSERT_CHUNK_SIZE);
|
||||
await localDb.insert(schema.account).values(chunk);
|
||||
}
|
||||
accountsCreated += accountsToInsert.length;
|
||||
|
||||
const batchEnd = performance.now();
|
||||
const batchTimeMs = batchEnd - batchStart;
|
||||
console.log(
|
||||
`✅ Bulk inserted ${usersToInsertData.length} users in ${batchTimeMs.toFixed(1)} ms (avg ${(batchTimeMs / usersToInsertData.length).toFixed(1)} ms/user)`,
|
||||
);
|
||||
const batchEnd = performance.now();
|
||||
const batchTimeMs = batchEnd - batchStart;
|
||||
console.log(
|
||||
`✅ Bulk inserted ${usersToInsertData.length} users in ${batchTimeMs.toFixed(1)} ms (avg ${(batchTimeMs / usersToInsertData.length).toFixed(1)} ms/user)`,
|
||||
);
|
||||
|
||||
// Save progress after each batch
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
} catch (error) {
|
||||
console.error(`🚨 Failed to bulk insert users batch:`, error);
|
||||
// Continue with next batch even if this one fails
|
||||
}
|
||||
// Save progress after each batch
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
} catch (error) {
|
||||
console.error(`🚨 Failed to bulk insert users batch:`, error);
|
||||
// Continue with next batch even if this one fails
|
||||
}
|
||||
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
// Update cursor to the last user in this batch
|
||||
const lastUser = users[users.length - 1];
|
||||
if (lastUser) {
|
||||
lastSeenCreatedAt =
|
||||
lastUser.createdAt instanceof Date ? lastUser.createdAt.toISOString() : String(lastUser.createdAt);
|
||||
lastSeenId = lastUser.id;
|
||||
}
|
||||
|
||||
totalUsersProcessed += users.length;
|
||||
console.log(`📦 Processed ${totalUsersProcessed} users so far...\n`);
|
||||
totalUsersProcessed += users.length;
|
||||
console.log(`📦 Processed ${totalUsersProcessed} users so far...\n`);
|
||||
|
||||
// Save progress after updating cursor
|
||||
await saveProgress(getCurrentProgress());
|
||||
}
|
||||
// Save progress after updating cursor
|
||||
await saveProgress(getCurrentProgress());
|
||||
}
|
||||
|
||||
// Remove signal handlers
|
||||
process.off("SIGINT", handleShutdown);
|
||||
process.off("SIGTERM", handleShutdown);
|
||||
// Remove signal handlers
|
||||
process.off("SIGINT", handleShutdown);
|
||||
process.off("SIGTERM", handleShutdown);
|
||||
|
||||
const migrationEnd = performance.now();
|
||||
const migrationDurationMs = migrationEnd - migrationStart;
|
||||
const migrationEnd = performance.now();
|
||||
const migrationDurationMs = migrationEnd - migrationStart;
|
||||
|
||||
console.log("\n📊 Migration Summary:");
|
||||
console.log(` Users created: ${usersCreated}`);
|
||||
console.log(` Accounts created: ${accountsCreated}`);
|
||||
console.log(` Skipped (already exist): ${skipped}`);
|
||||
console.log(
|
||||
`⏱️ Total migration time: ${migrationDurationMs.toFixed(1)} ms (${(migrationDurationMs / 1000).toFixed(2)} seconds)`,
|
||||
);
|
||||
console.log("\n📊 Migration Summary:");
|
||||
console.log(` Users created: ${usersCreated}`);
|
||||
console.log(` Accounts created: ${accountsCreated}`);
|
||||
console.log(` Skipped (already exist): ${skipped}`);
|
||||
console.log(
|
||||
`⏱️ Total migration time: ${migrationDurationMs.toFixed(1)} ms (${(migrationDurationMs / 1000).toFixed(2)} seconds)`,
|
||||
);
|
||||
|
||||
// Final save of the mapping (ensures up-to-date state)
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
// Final save of the mapping (ensures up-to-date state)
|
||||
await saveUserIdMapToFile(userIdMap);
|
||||
|
||||
// Clear progress file on successful completion (only if not interrupted)
|
||||
if (!shutdownRequested) {
|
||||
await clearProgress();
|
||||
console.log("✅ User migration complete!");
|
||||
} else {
|
||||
console.log("⏸️ Migration paused. Run again to resume.");
|
||||
}
|
||||
// Clear progress file on successful completion (only if not interrupted)
|
||||
if (!shutdownRequested) {
|
||||
await clearProgress();
|
||||
console.log("✅ User migration complete!");
|
||||
} else {
|
||||
console.log("⏸️ Migration paused. Run again to resume.");
|
||||
}
|
||||
|
||||
// Return the ID mapping for use in other migrations (e.g., resumes)
|
||||
return userIdMap;
|
||||
// Return the ID mapping for use in other migrations (e.g., resumes)
|
||||
return userIdMap;
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
// Reset shutdown flag for fresh run
|
||||
shutdownRequested = false;
|
||||
// Reset shutdown flag for fresh run
|
||||
shutdownRequested = false;
|
||||
|
||||
try {
|
||||
await migrateUsers();
|
||||
} finally {
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
}
|
||||
try {
|
||||
await migrateUsers();
|
||||
} finally {
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user