Skip to content

Commit

Permalink
fix onMigrate latest version bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Dec 5, 2024
1 parent 1931a57 commit fbe2c6b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/TableConfig/initTableConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
CREATE TABLE IF NOT EXISTS ${asName(versionTableName)}(id NUMERIC PRIMARY KEY, table_config JSONB NOT NULL)
`);
migrations = { version, table: versionTableName };
const maxVersion = (await this.db.oneOrNone(`SELECT MAX(id) as v FROM ${asName(versionTableName)}`)).v
const maxVersion = +(await this.db.oneOrNone(`SELECT MAX(id) as v FROM ${asName(versionTableName)}`)).v
const latestVersion = Number.isFinite(maxVersion) ? maxVersion : undefined;

if (latestVersion === version) {
Expand All @@ -70,7 +70,7 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
return;
}
}
if (!latestVersion || latestVersion < version) {
if (latestVersion !== undefined && latestVersion < version) {
await onMigrate({ db: this.db, oldVersion: latestVersion, getConstraints: (table, col, types) => getColConstraints({ db: this.db, table, column: col, types }) })
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.174",
"version": "4.2.175",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbe2c6b

Please sign in to comment.