diff --git a/integration-tests/__tests__/deploy-database.spec.js b/integration-tests/__tests__/deploy-database.spec.js index 8b41b322..416f904f 100644 --- a/integration-tests/__tests__/deploy-database.spec.js +++ b/integration-tests/__tests__/deploy-database.spec.js @@ -297,4 +297,33 @@ describe('Deploy database', () => { expect(res.rows[0].val.toString()).toEqual('5'); }) ); + + test.each(engines.enginesPostgre.map(engine => [engine.label, engine]))( + 'Current timestamp default value - %s', + testWrapper(async (conn, driver, engine) => { + await testDatabaseDeploy(conn, driver, [ + [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { + name: 'val', + type: 'timestamp', + default: 'current_timestamp', + }, + ], + primaryKey: ['id'], + }, + }, + ], + ]); + + await driver.query(conn, `insert into t1 (id) values (1)`); + const res = await driver.query(conn, ` select val from t1 where id = 1`); + expect(res.rows[0].val.toString().substring(0, 2)).toEqual('20'); + }) + ); }); diff --git a/integration-tests/engines.js b/integration-tests/engines.js index 5e8b57c0..8f10950d 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -141,6 +141,10 @@ const filterLocal = [ '-CockroachDB', ]; +const enginesPostgre = engines.filter(x => x.label == 'PostgreSQL'); + module.exports = process.env.CITEST ? engines.filter(x => !x.skipOnCI) : engines.filter(x => filterLocal.find(y => x.label == y)); + +module.exports.enginesPostgre = enginesPostgre; diff --git a/packages/tools/src/yamlModelConv.ts b/packages/tools/src/yamlModelConv.ts index d22fbd4f..bf0c5798 100644 --- a/packages/tools/src/yamlModelConv.ts +++ b/packages/tools/src/yamlModelConv.ts @@ -1,4 +1,5 @@ import { ColumnInfo, TableInfo, ForeignKeyInfo, DatabaseInfo } from 'dbgate-types'; +import { StringNullableChain } from 'lodash'; import _cloneDeep from 'lodash/cloneDeep'; import _compact from 'lodash/compact'; import { DatabaseAnalyser } from './DatabaseAnalyser'; @@ -11,6 +12,7 @@ export interface ColumnInfoYaml { autoIncrement?: boolean; references?: string; primaryKey?: boolean; + default?: string; } export interface DatabaseModelFile { @@ -39,6 +41,7 @@ function columnInfoToYaml(column: ColumnInfo, table: TableInfo): ColumnInfoYaml const res: ColumnInfoYaml = { name: column.columnName, type: column.dataType, + default: column.defaultValue, }; if (column.autoIncrement) res.autoIncrement = true; if (column.notNull) res.notNull = true; @@ -71,6 +74,7 @@ function columnInfoFromYaml(column: ColumnInfoYaml, table: TableInfoYaml): Colum dataType: column.length ? `${column.type}(${column.length})` : column.type, autoIncrement: column.autoIncrement, notNull: column.notNull || (table.primaryKey && table.primaryKey.includes(column.name)), + defaultValue: column.default, }; return res; }