Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions forge/ee/lib/tables/drivers/postgres-localfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
}
Expand Down
4 changes: 2 additions & 2 deletions forge/ee/lib/tables/drivers/postgres-supavisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/forge/ee/lib/tables/drivers/postgres-localfs_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/forge/ee/lib/tables/drivers/postgres-supavisor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Loading