Add skip logic to migration scripts to prevent re-running
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -49,3 +49,4 @@ next-env.d.ts
|
|||||||
!/public/uploads/.gitkeep
|
!/public/uploads/.gitkeep
|
||||||
/data
|
/data
|
||||||
.release-years-migrated
|
.release-years-migrated
|
||||||
|
.covers-migrated
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
import { parseBuffer } from 'music-metadata';
|
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 path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
@@ -11,6 +11,16 @@ const __dirname = path.dirname(__filename);
|
|||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
async function migrate() {
|
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...');
|
console.log('Starting cover art migration...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -55,6 +65,10 @@ async function migrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Migration completed.');
|
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) {
|
} catch (e) {
|
||||||
console.error('Migration failed:', e);
|
console.error('Migration failed:', e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -122,6 +122,18 @@ async function getReleaseYear(artist, title) {
|
|||||||
// --- Migration Logic ---
|
// --- Migration Logic ---
|
||||||
|
|
||||||
async function migrate() {
|
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('🎵 Starting release year migration...');
|
||||||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user