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
44 lines
1.3 KiB
Plaintext
44 lines
1.3 KiB
Plaintext
import { Table } from 'console-table-printer';
|
|
import { getMigrations, readMigrationFiles } from 'payload';
|
|
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
export async function migrateStatus() {
|
|
const { payload } = this;
|
|
const migrationFiles = await readMigrationFiles({
|
|
payload
|
|
});
|
|
payload.logger.debug({
|
|
msg: `Found ${migrationFiles.length} migration files.`
|
|
});
|
|
let existingMigrations = [];
|
|
const hasMigrationTable = await migrationTableExists(this);
|
|
if (hasMigrationTable) {
|
|
;
|
|
({ existingMigrations } = await getMigrations({
|
|
payload
|
|
}));
|
|
}
|
|
if (!migrationFiles.length) {
|
|
payload.logger.info({
|
|
msg: 'No migrations found.'
|
|
});
|
|
return;
|
|
}
|
|
// Compare migration files to existing migrations
|
|
const statuses = migrationFiles.map((migration)=>{
|
|
const existingMigration = existingMigrations.find((m)=>m.name === migration.name);
|
|
return {
|
|
Name: migration.name,
|
|
Batch: existingMigration?.batch,
|
|
Ran: existingMigration ? 'Yes' : 'No'
|
|
};
|
|
});
|
|
const p = new Table();
|
|
statuses.forEach((s)=>{
|
|
p.addRow(s, {
|
|
color: s.Ran === 'Yes' ? 'green' : 'red'
|
|
});
|
|
});
|
|
p.printTable();
|
|
}
|
|
|
|
//# sourceMappingURL=migrateStatus.js.map |