Browse Source

feat(core): Check migration status in the `runMigrations()` util function

Michael Bromley 3 years ago
parent
commit
ca72de557f
1 changed files with 15 additions and 0 deletions
  1. 15 0
      packages/core/src/migrate.ts

+ 15 - 0
packages/core/src/migrate.ts

@@ -52,11 +52,26 @@ export async function runMigrations(userConfig: Partial<VendureConfig>) {
         console.log(e.message);
         console.log(e.message);
         process.exitCode = 1;
         process.exitCode = 1;
     } finally {
     } finally {
+        await checkMigrationStatus(connection);
         await connection.close();
         await connection.close();
         resetConfig();
         resetConfig();
     }
     }
 }
 }
 
 
+async function checkMigrationStatus(connection: Connection) {
+    const builderLog = await connection.driver.createSchemaBuilder().log();
+    if (builderLog.upQueries.length) {
+        console.log(
+            chalk.yellow(
+                `Your database schema does not match your current configuration. Generate a new migration for the following changes:`,
+            ),
+        );
+        for (const query of builderLog.upQueries) {
+            console.log(' - ' + chalk.yellow(query.query));
+        }
+    }
+}
+
 /**
 /**
  * @description
  * @description
  * Reverts the last applied database migration. See [TypeORM migration docs](https://typeorm.io/#/migrations)
  * Reverts the last applied database migration. See [TypeORM migration docs](https://typeorm.io/#/migrations)