问题
Sorry, this question seems stupid, but I tried 1 hour searching and didn't find anything. So I'm using liquibase for multiple databases(e.g. MSSQL, Oracle and MySQL), when I say:
addColumn(tableName: "ABC_TEST") {
column(name: "IS_ACTIVE", type: "boolean")
}
How do I know if the type "boolean" will be converted to proper types for each database? And is there any documentation I can find for the data type mapping? If I want to add one more column which is foreign key, which type should I use?
回答1:
Checkout this question (and answers) to see the available types that liquibase offers.
In my answer to that question there is a link to the relevant liquibase classes that do the translation to the db specific types.
When you created the table that has the primary key with a "liquibase type" then liquibase will have translated this to the db specific type. Then your foreign key should just use the same type and liquibase will translate this likewise.
E.g. check out the class BigIntType.
With liquibase you would just use the "liquibase type": BIGINT
.
On Oracle DBs it will translate to ("NUMBER", 38,0)
.
On MSSQL it will translate to ("BIGINT")
.
回答2:
Liquibase has a concept of database dialects, much like Hibernate's. It uses these to know how to generate the correct DDL statements to add/change/delete columns, foreign keys, etc. When it connects to the database it uses the JDBC metadata to determine which database type you're using, and uses that to determine the correct dialect.
回答3:
Here is a table with Liquibase data types mapping to SQL Server and Oracle.
||Liquibase data type||SQL Server data type||Oracle data type||
|bigint|bigint|number(38,0)|
|blob|varbinary(max)|blob|
|boolean|bit|number(1)|
|char|char|char|
|clob|nvarchar(max)|clob|
|currency|money|number(15,2)|
|datetime|smalldatetime or datetime2|timestamp|
|date|date or smalldatetime (version <= 2005)|date|
|decimal|decimal|decimal|
|double|float|float(24)|
|float|float|float|
|int|int|number(10)|
|mediumint|mediumint|mediumint|
|nchar|nchar|nchar|
|nvarchar|nvarchar|nvarchar2|
|number|numeric|number|
|smallint|smallint|number(5)|
|time|time or datetime (version <= 2005)|date|
|timestamp|datetime|timestamp|
|tinyint|tinyint|number(3)|
|uuid|uniqueidentifier|raw(16)|
|varchar|varchar|varchar2|
来源:https://stackoverflow.com/questions/17287001/liquibase-data-type-mapping-documentation