Liquibase 如何为 Oracle 映射布尔值?
How does Liquibase map boolean for oracle?
已知事实:Oracle 本身不支持布尔值。
因此建议使用 Char(1) 或 Number(1),然后创建约束以将值限制为 Y/N 或 0/1.
话虽这么说。
为 oracle 数据库创建布尔值时,Liquibase 创建一个数字 (1)。
有谁知道它是否还会创建数据库约束?
即:"check (bool in (0,1))"
http://dba-presents.com/index.php/liquibase/29-liquibase-3-3-x-data-types-mapping-table
创建更新日志:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet author="arthur" id="42">
<createTable tableName="bool_test">
<column name="some_flag" type="boolean"/>
</createTable>
</changeSet>
</databaseChangeLog>
运行 脚本
liquibase --changeLogFile=bool_test.xml update
显示 table 定义
c:>sqlplus arthur/password
SQL*Plus: Release 12.1.0.1.0 Production on Tue Dec 20 18:19:21 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select dbms_metadata.get_ddl('TABLE', 'BOOL_TEST') from dual;
DBMS_METADATA.GET_DDL('TABLE','BOOL_TEST')
--------------------------------------------------------------------------------
CREATE TABLE "ARTHUR"."BOOL_TEST"
( "SOME_FLAG" NUMBER(1,0)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS"
已知事实:Oracle 本身不支持布尔值。 因此建议使用 Char(1) 或 Number(1),然后创建约束以将值限制为 Y/N 或 0/1.
话虽这么说。 为 oracle 数据库创建布尔值时,Liquibase 创建一个数字 (1)。 有谁知道它是否还会创建数据库约束? 即:"check (bool in (0,1))"
http://dba-presents.com/index.php/liquibase/29-liquibase-3-3-x-data-types-mapping-table
创建更新日志:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet author="arthur" id="42">
<createTable tableName="bool_test">
<column name="some_flag" type="boolean"/>
</createTable>
</changeSet>
</databaseChangeLog>
运行 脚本
liquibase --changeLogFile=bool_test.xml update
显示 table 定义
c:>sqlplus arthur/password
SQL*Plus: Release 12.1.0.1.0 Production on Tue Dec 20 18:19:21 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select dbms_metadata.get_ddl('TABLE', 'BOOL_TEST') from dual;
DBMS_METADATA.GET_DDL('TABLE','BOOL_TEST')
--------------------------------------------------------------------------------
CREATE TABLE "ARTHUR"."BOOL_TEST"
( "SOME_FLAG" NUMBER(1,0)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS"