mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Make migration logs more explicit
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import run from '../../../database/migrations/run';
|
||||
|
||||
import ora from 'ora';
|
||||
|
||||
export default async function migrate(direction: 'latest' | 'up' | 'down') {
|
||||
const database = require('../../../database').default;
|
||||
|
||||
try {
|
||||
const spinnerDriver = ora('Running migrations...').start();
|
||||
console.log('✨ Running migrations...');
|
||||
|
||||
await run(database, direction);
|
||||
spinnerDriver.stop();
|
||||
|
||||
if (direction === 'down') {
|
||||
console.log('✨ Downgrade successful');
|
||||
|
||||
@@ -64,6 +64,9 @@ export default async function run(database: Knex, direction: 'up' | 'down' | 'la
|
||||
}
|
||||
|
||||
const { up } = require(nextVersion.file);
|
||||
|
||||
console.log(`✨ Applying ${nextVersion.name}...`);
|
||||
|
||||
await up(database);
|
||||
await database.insert({ version: nextVersion.version, name: nextVersion.name }).into('directus_migrations');
|
||||
}
|
||||
@@ -78,10 +81,13 @@ export default async function run(database: Knex, direction: 'up' | 'down' | 'la
|
||||
const migration = migrations.find((migration) => migration.version === currentVersion.version);
|
||||
|
||||
if (!migration) {
|
||||
throw new Error('Couldnt find migration');
|
||||
throw new Error("Couldn't find migration");
|
||||
}
|
||||
|
||||
const { down } = require(migration.file);
|
||||
|
||||
console.log(`✨ Undoing ${migration.name}...`);
|
||||
|
||||
await down(database);
|
||||
await database('directus_migrations').delete().where({ version: migration.version });
|
||||
}
|
||||
@@ -90,6 +96,9 @@ export default async function run(database: Knex, direction: 'up' | 'down' | 'la
|
||||
for (const migration of migrations) {
|
||||
if (migration.completed === false) {
|
||||
const { up } = require(migration.file);
|
||||
|
||||
console.log(`✨ Applying ${migration.name}...`);
|
||||
|
||||
await up(database);
|
||||
await database.insert({ version: migration.version, name: migration.name }).into('directus_migrations');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user