Skip to content

Commit

Permalink
fix(core): Use correct config & output path when generating migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Nov 20, 2019
1 parent 90e161b commit 637c863
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/core/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function revertLastMigration(userConfig: Partial<VendureConfig>) {
*/
export async function generateMigration(userConfig: Partial<VendureConfig>, options: MigrationOptions) {
const config = await preBootstrapConfig(userConfig);
const connection = await createConnection(createConnectionOptions(userConfig));
const connection = await createConnection(createConnectionOptions(config));

// TODO: This can hopefully be simplified if/when TypeORM exposes this CLI command directly.
// See https://github.com/typeorm/typeorm/issues/4494
Expand Down Expand Up @@ -125,18 +125,16 @@ export async function generateMigration(userConfig: Partial<VendureConfig>, opti
const filename = timestamp + '-' + options.name + '.ts';
const directory = options.outputDir;
const fileContent = getTemplate(options.name as any, timestamp, upSqls, downSqls.reverse());
const outputPath = path.join(process.cwd(), directory ? directory + '/' : '', filename);
const outputPath = directory
? path.join(directory, filename)
: path.join(process.cwd(), filename);
await fs.ensureFile(outputPath);
await fs.writeFileSync(outputPath, fileContent);

console.log(chalk.green(`Migration ${chalk.blue(outputPath)} has been generated successfully.`));
}
} else {
console.log(
chalk.yellow(
`No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command`,
),
);
console.log(chalk.yellow(`No changes in database schema were found - cannot generate a migration.`));
}
await connection.close();
}
Expand Down

0 comments on commit 637c863

Please sign in to comment.