diff --git a/lib/ddl.js b/lib/ddl.js index 2ae688a..ae4874f 100644 --- a/lib/ddl.js +++ b/lib/ddl.js @@ -98,15 +98,15 @@ class PgSchema extends DatabaseSchema { } } +DatabaseSchema.implementations.pg = PgSchema; + const generate = async (schemaPath, outputPath) => { const schema = await new PgSchema(schemaPath); - await schema.preprocess(); await schema.generate(outputPath); }; const migrate = async schemaPath => { const schema = await new PgSchema(schemaPath); - await schema.preprocess(); await schema.migrate(); }; diff --git a/lib/schema-db.js b/lib/schema-db.js index 6c43b1f..ca51578 100644 --- a/lib/schema-db.js +++ b/lib/schema-db.js @@ -29,6 +29,7 @@ class DatabaseSchema { const schemaName = path.basename(file.name, '.js'); this.entities.set(schemaName, schema); } + await this.preprocess(); return this; } @@ -102,7 +103,9 @@ class DatabaseSchema { } if (version === 0) return null; const previousPath = path.join(historyPath, previousName); - return new DatabaseSchema(previousPath); + const { driver } = this.database; + const SchemaClass = DatabaseSchema.implementations[driver]; + return new SchemaClass(previousPath); } async migrate() { @@ -127,4 +130,6 @@ class DatabaseSchema { } } +DatabaseSchema.implementations = {}; + module.exports = { DatabaseSchema };