Files
klz-cables.com/.pnpm-store/v10/files/c1/01d26e832d6577fcd9a7afb55439f35d5292356302b9d4645cf1183132e45726baf28e4240f1c977a1af8bf0f208e18d9e577e7057741cb62e8d21a8c894fa
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

86 lines
2.8 KiB
Plaintext

import { commitTransaction, createLocalReq, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
import { getTransaction } from './utilities/getTransaction.js';
import { migrationTableExists } from './utilities/migrationTableExists.js';
/**
* Run all migrate down functions
*/ export async function migrateReset() {
const { payload } = this;
const migrationFiles = await readMigrationFiles({
payload
});
const { existingMigrations } = await getMigrations({
payload
});
if (!existingMigrations?.length) {
payload.logger.info({
msg: 'No migrations to reset.'
});
return;
}
const req = await createLocalReq({}, payload);
existingMigrations.reverse();
// Rollback all migrations in order
for (const migration of existingMigrations){
const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
try {
if (!migrationFile) {
throw new Error(`Migration ${migration.name} not found locally.`);
}
const start = Date.now();
payload.logger.info({
msg: `Migrating down: ${migrationFile.name}`
});
await initTransaction(req);
const db = await getTransaction(this, req);
await migrationFile.down({
db,
payload,
req
});
payload.logger.info({
msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`
});
const tableExists = await migrationTableExists(this, db);
if (tableExists) {
await payload.delete({
id: migration.id,
collection: 'payload-migrations',
req
});
}
await commitTransaction(req);
} catch (err) {
let msg = `Error running migration ${migrationFile.name}.`;
if (err instanceof Error) {
msg += ` ${err.message}`;
}
await killTransaction(req);
payload.logger.error({
err,
msg
});
process.exit(1);
}
}
// Delete dev migration
const tableExists = await migrationTableExists(this);
if (tableExists) {
try {
await payload.delete({
collection: 'payload-migrations',
where: {
batch: {
equals: -1
}
}
});
} catch (err) {
payload.logger.error({
err,
msg: 'Error deleting dev migration'
});
}
}
}
//# sourceMappingURL=migrateReset.js.map