【发布时间】:2020-03-08 00:48:57
【问题描述】:
将 liquibase-core:3.6.3 与 MySQL 一起使用。
我第一次必须对列使用时间戳(3),而不是默认时间戳。由于我的时间戳列不可为空,如果未设置 DEFAULT 值,则添加 current_timestamp(直接在 MySQL 中或使用 liquibase)。
不是我面临 liquibase 生成的 SQL 不使用 CURRENT_TIMESTAMP 而是使用 NOW() 作为要调用的默认函数的问题。这使得时间戳(3)不可能。
有没有办法强制 liquibase 在输出中使用 CURRENT_TIMESTAMP 而不是 NOW()?
- changeSet:
id: xxx
author: xxx
changes:
- createTable:
tableName: table_name
columns:
- column:
name: id
type: int unsigned
autoIncrement: false
constraints:
primaryKey: true
- column:
name: updated
type: timestamp
defaultValueComputed: current_timestamp
constraints:
nullable: false
输出: CREATE TABLE db_name.table_name(id INT unsigned NOT NULL, updated timestamp DEFAULT NOW() NOT NULL, CONSTRAINT PK_RULE_STATE PRIMARY KEY (id));
这很好用。但是,将timestamp 更改为timestamp(3)
输出: CREATE TABLE db_name.table_name(id INT unsigned NOT NULL, updated timestamp(3) DEFAULT NOW() NOT NULL, CONSTRAINT PK_RULE_STATE PRIMARY KEY (id)); 其中 NOW() 不是有效值。
使用defaultValueDate进行相同的输出
如果我使用defaultValue: current_timestamp(),liquibase 足够聪明,可以将其检测为函数,因为它不使用文字字符串,但是,这仍然是 timestamp(3) 的重要值。最后,使用
- changeSet:
id: xxx
author: xxx
changes:
- createTable:
tableName: table_name
columns:
- column:
name: id
type: int unsigned
autoIncrement: false
constraints:
primaryKey: true
- column:
name: updated
type: timestamp(3)
defaultValue: current_timestamp(3)
constraints:
nullable: false
产生输出:
CREATE TABLE db_name.table_name(id INT unsigned NOT NULL, updated timestamp(3) DEFAULT DEFAULT 'current_timestamp(3)' NOT NULL, CONSTRAINT PK_RULE_STATE PRIMARY KEY (id));
我最后的机会是根本没有设置默认值。除了as this guy said long ago,MySQL 添加了ON UPDATE CURRENT_TIMESTAMP(3) 而我无法避免它之外,这很好用。
那么,有没有办法强制使用 current_timestamp(3) 或作为备份计划,以防止 MySQL 生成 ON UPDATE 部分?
【问题讨论】:
标签: mysql timestamp liquibase liquibase-hibernate liquibase-sql