Files
klz-cables.com/.pnpm-store/v10/files/59/15b4ef206df69bc3b8fd1a4d1c3daf988f401af368188558e427e71884ca6361958a9a50bd0c96bf2093d5685bce3be0b103394c0a2c19a4f428d335ad272c
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

77 lines
2.5 KiB
Plaintext

import { commitTransaction, createLocalReq, initTransaction, killTransaction, readMigrationFiles } from 'payload';
import prompts from 'prompts';
import { getTransaction } from './utilities/getTransaction.js';
import { parseError } from './utilities/parseError.js';
/**
* Drop the current database and run all migrate up functions
*/ export async function migrateFresh({ forceAcceptWarning = false }) {
const { payload } = this;
if (forceAcceptWarning === false) {
const { confirm: acceptWarning } = await prompts({
name: 'confirm',
type: 'confirm',
initial: false,
message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
}, {
onCancel: ()=>{
process.exit(0);
}
});
if (!acceptWarning) {
process.exit(0);
}
}
payload.logger.info({
msg: `Dropping database.`
});
await this.dropDatabase({
adapter: this
});
const migrationFiles = await readMigrationFiles({
payload
});
payload.logger.debug({
msg: `Found ${migrationFiles.length} migration files.`
});
const req = await createLocalReq({}, payload);
if ('createExtensions' in this && typeof this.createExtensions === 'function') {
await this.createExtensions();
}
// Run all migrate up
for (const migration of migrationFiles){
payload.logger.info({
msg: `Migrating: ${migration.name}`
});
try {
const start = Date.now();
await initTransaction(req);
const db = await getTransaction(this, req);
await migration.up({
db,
payload,
req
});
await payload.create({
collection: 'payload-migrations',
data: {
name: migration.name,
batch: 1
},
req
});
await commitTransaction(req);
payload.logger.info({
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
});
} catch (err) {
await killTransaction(req);
payload.logger.error({
err,
msg: parseError(err, `Error running migration ${migration.name}. Rolling back`)
});
process.exit(1);
}
}
}
//# sourceMappingURL=migrateFresh.js.map