Add skip logic to migration scripts to prevent re-running
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { parseBuffer } from 'music-metadata';
|
||||
import { readFile, writeFile, mkdir } from 'fs/promises';
|
||||
import { readFile, writeFile, mkdir, access } from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
@@ -11,6 +11,16 @@ const __dirname = path.dirname(__filename);
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function migrate() {
|
||||
// Check if migration already ran
|
||||
const flagPath = path.join(process.cwd(), '.covers-migrated');
|
||||
try {
|
||||
await access(flagPath);
|
||||
console.log('✅ Cover migration already completed (flag file exists). Skipping...');
|
||||
return;
|
||||
} catch {
|
||||
// Flag file doesn't exist, proceed with migration
|
||||
}
|
||||
|
||||
console.log('Starting cover art migration...');
|
||||
|
||||
try {
|
||||
@@ -55,6 +65,10 @@ async function migrate() {
|
||||
}
|
||||
|
||||
console.log('Migration completed.');
|
||||
|
||||
// Create flag file to prevent re-running
|
||||
await writeFile(flagPath, new Date().toISOString());
|
||||
console.log(`🏁 Created flag file: ${flagPath}`);
|
||||
} catch (e) {
|
||||
console.error('Migration failed:', e);
|
||||
} finally {
|
||||
|
||||
@@ -122,6 +122,18 @@ async function getReleaseYear(artist, title) {
|
||||
// --- Migration Logic ---
|
||||
|
||||
async function migrate() {
|
||||
// Check if migration already ran
|
||||
const flagPath = path.join(process.cwd(), '.release-years-migrated');
|
||||
try {
|
||||
const { access } = await import('fs/promises');
|
||||
await access(flagPath);
|
||||
console.log('✅ Release year migration already completed (flag file exists). Skipping...');
|
||||
await prisma.$disconnect();
|
||||
return;
|
||||
} catch {
|
||||
// Flag file doesn't exist, proceed with migration
|
||||
}
|
||||
|
||||
console.log('🎵 Starting release year migration...');
|
||||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user