-
Hi ! i am trying if i can achive the following, i am not sure if
|
Beta Was this translation helpful? Give feedback.
Answered by
shrynx
Aug 27, 2024
Replies: 1 comment
-
added the following as a provider and it works well import app from "@adonisjs/core/services/app";
import type { ApplicationService } from "@adonisjs/core/types";
import { MigrationRunner } from "@adonisjs/lucid/migration";
import db from "@adonisjs/lucid/services/db";
export default class MigrationCheckProvider {
constructor(protected app: ApplicationService) {}
async start() {
if (this.app.getEnvironment() === "web") {
const migrator = new MigrationRunner(db, app, {
direction: "up",
dryRun: true,
});
const migrations = await migrator.getList();
const incompleteMigrations = migrations.filter(
(m) => m.status !== "migrated",
);
if (incompleteMigrations.length > 0) {
console.error(
`Pending Migrations${incompleteMigrations.map((m) => `\n${m.name} - ${m.status}`)}`,
);
if (app.inProduction) {
console.error("Exiting due to pending migrations");
process.exit(1);
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
shrynx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added the following as a provider and it works well