Last active
April 24, 2018 17:03
-
-
Save brianv0/93c9bfe32317c44a498f5fe2f9dc8e95 to your computer and use it in GitHub Desktop.
Generate Database Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.liquibase:liquibase-core:3.5.1') | |
import liquibase.database.core.* | |
import liquibase.datatype.core.* | |
def datatypes = [BooleanType,TinyIntType,SmallIntType,IntType,BigIntType, | |
FloatType,DoubleType,DecimalType,NumberType, | |
CharType,VarcharType,NCharType,NVarcharType, | |
DateTimeType,TimeType,TimestampType,DateType, | |
ClobType,BlobType,UUIDType] | |
def databases = [MySQLDatabase, SQLiteDatabase, OracleDatabase, PostgresDatabase] | |
def mappings = [ | |
'tinyint': 'byte', | |
'smallint': 'short', | |
'bigint': 'long', | |
'varchar': 'string', | |
'nvarchar': 'unicode', | |
'blob': 'binary', | |
'clob': 'text' | |
] | |
databases.each { | |
println "$it.simpleName" | |
datatypes.each { dt -> | |
def datatype = dt.newInstance() | |
datatype.finishInitialization("") | |
if (mappings["$datatype.name"]) { | |
print mappings["$datatype.name"] + ": " | |
} else { | |
print "$datatype.name: " | |
} | |
println "${datatype.toDatabaseDataType(it.newInstance())}" | |
} | |
println '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment