I’m a certified SQL Server DBA, a certified Oracle DBA, and I’ve used liquibase before, so I thought that using liquibase to migrate a schema definition from SQL Server to Oracle was going to be trivial. I was surprised at how much work was involved.
Please note that this process does not copy any data, it just copies the empty structures.
- I already had liquibase. Liquibase is just a download with no install.
- I did need to configure liquibase. I keep one .properties file for each of my databases. They are:
- MS SQL
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver classpath=C:\\Program Files\\Microsoft JDBC Driver 4.1 for SQL Server\\sqljdbc_4.1\\enu\\sqljdbc41.jar url=jdbc:sqlserver://192.168.0.106 username=Liquibase password=YourPasswordHere changeLogFile=C:\\Git\\ChangeLog.xml
Notice that:
- I’ve downloaded and unzipped the Microsoft JDBC
- The double slashes in the classpath
- the JDBC URL is my SQL Server, on which I am using the default instance.
- I’ve used SQL Server authentication, rather than windows authentication
- Oracle
driver: oracle.jdbc.OracleDriver classpath: C:\\oracle\\instantclient_12_1\\ojdbc7.jar url: jdbc:oracle:thin:@YourDBHostname:1521:ORCL username=YourUsernameHere password=YourPasswordHere changeLogFile=C:\\Git\\ChangeLog.xml logFile=C:\\Program Files\\liquibase-3.3.5-bin\\liquibase.log logLevel=info
Notice that:
- I’ve also downloaded and installed the instant client for Oracle.
- Again the double slashes in the classpath.
- That I’ve kept the same changeLogFile.
- That I set the log as you’ll probably need to look through that.
- MS SQL
- Copy mssql.properties to liquibase.properties. Then reverse-engineer your database with generateChangeLog.
liquibase generateChangeLog
- Now comes the step that I wasn’t expecting. The liquibase change log is a lot more database dependent than I was expecting. Before you can apply it to Oracle you’ll need to:
- remove
Autoincrement
from columns - examine the
Default
values for database specific functions. i.e.USER
in Oracle vscurrent_user()
in SQL Server. - Manually convert “user defined” types used for SQL Server columns. Including types that shipped with SQL Server like
SYSNAME
. - Manually convert
DATETIMEOFFSET
toDATE
orTIMESTAMP
as is appropriate.
- remove
- Now copy over liquibase.properties with your Oracle.properties file and update your Oracle database.
liquibase update
- Finally, you’ll need to generate sequences and before-insert-row triggers for the SQL Server identity columns we removed earlier. You can write your own dynamic-SQL generator or just let Freeware Toad do that for you.
This process is far from ideal. I appreciate that this isn’t a core feature of liquibase, just a trick that it doesn’t prevent. I’m inclined to believe that there are other tools that do this task better, I just don’t happen to know of any that are free. It may not be pretty, but liquibase will port your tables from Microsoft SQL Server to Oracle.
-Steven