From 2c211d4730494018e7c2e755fbd2aeb4b5515c8d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 1 Mar 2021 22:40:13 -0500 Subject: [PATCH] Fix preprocessor not being used for initial schema --- src/databases/Postgres.ts | 4 ++++ src/databases/Sqlite.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index 6001a38..1bb4e08 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -15,6 +15,10 @@ export class Mysql implements IDatabase { if (!this.config.readOnly) { // Upgrade database if required this.upgradeDB(this.config.fileNamePrefix, this.config.dbSchemaFolder); + + if (this.config.createDbIfNotExists && !this.config.readOnly && fs.existsSync(this.config.dbSchemaFileName)) { + this.pool.query(this.processUpgradeQuery(fs.readFileSync(this.config.dbSchemaFileName).toString())); + } } } diff --git a/src/databases/Sqlite.ts b/src/databases/Sqlite.ts index 1ef1823..b2880a2 100644 --- a/src/databases/Sqlite.ts +++ b/src/databases/Sqlite.ts @@ -50,7 +50,7 @@ export class Sqlite implements IDatabase { this.db = new Sqlite3(this.config.dbPath, {readonly: this.config.readOnly, fileMustExist: !this.config.createDbIfNotExists}); if (this.config.createDbIfNotExists && !this.config.readOnly && fs.existsSync(this.config.dbSchemaFileName)) { - this.db.exec(fs.readFileSync(this.config.dbSchemaFileName).toString()); + this.db.exec(Sqlite.processUpgradeQuery(fs.readFileSync(this.config.dbSchemaFileName).toString())); } if (!this.config.readOnly) {