Skip to content

Commit

Permalink
feat: use strategies DatabaseSchema.implementations
Browse files Browse the repository at this point in the history
Refs: #23
  • Loading branch information
tshemsedinov committed Sep 12, 2020
1 parent 925ed65 commit 6c145ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ddl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
7 changes: 6 additions & 1 deletion lib/schema-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DatabaseSchema {
const schemaName = path.basename(file.name, '.js');
this.entities.set(schemaName, schema);
}
await this.preprocess();
return this;
}

Expand Down Expand Up @@ -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() {
Expand All @@ -127,4 +130,6 @@ class DatabaseSchema {
}
}

DatabaseSchema.implementations = {};

module.exports = { DatabaseSchema };

0 comments on commit 6c145ad

Please sign in to comment.