diff --git a/forge/ee/lib/tables/drivers/postgres-localfs.js b/forge/ee/lib/tables/drivers/postgres-localfs.js index 8eb9f21f9d..2dc7c0ca11 100644 --- a/forge/ee/lib/tables/drivers/postgres-localfs.js +++ b/forge/ee/lib/tables/drivers/postgres-localfs.js @@ -299,9 +299,9 @@ module.exports = { } else if (col.type === 'bigint') { column += `DEFAULT ${parseInt(col.default)}` } else if (['real', 'double precision'].includes(col.type)) { - column += `DEFAULT ${parseFloat(column.default)}` + column += `DEFAULT ${parseFloat(col.default)}` } else if (col.type === 'boolean') { - column += `DEFAULT ${column.default === 'true'}` + column += `DEFAULT ${col.default === 'true'}` } else if (col.type === 'timestamptz') { column += 'DEFAULT NOW()' } diff --git a/forge/ee/lib/tables/drivers/postgres-supavisor.js b/forge/ee/lib/tables/drivers/postgres-supavisor.js index 649432ec03..e93c5e4e68 100644 --- a/forge/ee/lib/tables/drivers/postgres-supavisor.js +++ b/forge/ee/lib/tables/drivers/postgres-supavisor.js @@ -372,9 +372,9 @@ module.exports = { } else if (col.type === 'bigint') { column += `DEFAULT ${parseInt(col.default)}` } else if (['real', 'double precision'].includes(col.type)) { - column += `DEFAULT ${parseFloat(column.default)}` + column += `DEFAULT ${parseFloat(col.default)}` } else if (col.type === 'boolean') { - column += `DEFAULT ${column.default === 'true'}` + column += `DEFAULT ${col.default === 'true'}` } else if (col.type === 'timestamptz') { column += 'DEFAULT NOW()' } diff --git a/test/unit/forge/ee/lib/tables/drivers/postgres-localfs_spec.js b/test/unit/forge/ee/lib/tables/drivers/postgres-localfs_spec.js index a14d5d012a..1487fb6c06 100644 --- a/test/unit/forge/ee/lib/tables/drivers/postgres-localfs_spec.js +++ b/test/unit/forge/ee/lib/tables/drivers/postgres-localfs_spec.js @@ -449,6 +449,17 @@ describe('Tables: Postgres LocalFS Driver', function () { await driver.createTable(team, team.hashid, 'table1', columns, 'reports').should.be.rejectedWith(/boom/) query.lastCall.args[0].should.equal('ROLLBACK') }) + it('should apply the defaults of real, double precision and boolean columns', async function () { + const team = { id: 1, hashid: 't1hash' } + await driver.init(app, options) + const query = setup(team) + await driver.createTable(team, team.hashid, 'table1', [ + { name: 'r', type: 'real', default: '1.5' }, + { name: 'd', type: 'double precision', default: '2.25' }, + { name: 'b', type: 'boolean', default: 'true' } + ]) + query.args[1][0].should.equal('CREATE TABLE IF NOT EXISTS "public"."table1" (\n"r" real NOT NULL DEFAULT 1.5,\n"d" double precision NOT NULL DEFAULT 2.25,\n"b" boolean NOT NULL DEFAULT true\n)') + }) }) describe('dropTable', function () { diff --git a/test/unit/forge/ee/lib/tables/drivers/postgres-supavisor_spec.js b/test/unit/forge/ee/lib/tables/drivers/postgres-supavisor_spec.js index c44b8f0470..907d657389 100644 --- a/test/unit/forge/ee/lib/tables/drivers/postgres-supavisor_spec.js +++ b/test/unit/forge/ee/lib/tables/drivers/postgres-supavisor_spec.js @@ -488,6 +488,17 @@ describe('Tables: Postgres Supavisor Driver', function () { await driver.createTable(team, team.hashid, 'table1', columns, 'reports').should.be.rejectedWith(/boom/) query.lastCall.args[0].should.equal('ROLLBACK') }) + it('should apply the defaults of real, double precision and boolean columns', async function () { + const team = { id: 1, hashid: 't1hash' } + await driver.init(app, options) + const query = setup(team) + await driver.createTable(team, team.hashid, 'table1', [ + { name: 'r', type: 'real', default: '1.5' }, + { name: 'd', type: 'double precision', default: '2.25' }, + { name: 'b', type: 'boolean', default: 'true' } + ]) + query.args[1][0].should.equal('CREATE TABLE IF NOT EXISTS "public"."table1" (\n"r" real NOT NULL DEFAULT 1.5,\n"d" double precision NOT NULL DEFAULT 2.25,\n"b" boolean NOT NULL DEFAULT true\n)') + }) }) describe('dropTable', function () {