Database Migration

后端 未结 4 869
太阳男子
太阳男子 2021-02-03 15:59

I am working on database migration tool in java. The tool is copying database tables with their data\'s to the destination database. But I want it to work on different databases

相关标签:
4条回答
  • 2021-02-03 16:10

    Try SchemaCrawler, which is also open source, and written in Java. It provides programmatic access to database metadata, and also allows scripting in JavaScript. http://schemacrawler.sourceforge.net/

    0 讨论(0)
  • 2021-02-03 16:19

    try to see what HIBERNATE provides for migration. I know that H can generate model objects from database schema and a schema from model objects. So maybe you can reuse some parts from HIBERNATE. They have the notion of DIALECT that does exactly what you are saying: defining specifics of a db implementation.

    0 讨论(0)
  • 2021-02-03 16:23

    Apache's DdlUtils is done what I need. When I am searching about crossdb found it, and it is very useful yet powerful. It can generate a database from scratch, just with the parameters. Or it can grab existing database table definitions, also with index definitions. You can use delimiter if you want (it is a deadly important option for me to use Apache Derby). You can just print out these definitions or apply them directly to source database (I haven't tried the second one yet). It translates definitions for the selected database. But one big problem is there is no good tutorial about how to start using it. I searched through the packages to find a good place to start. Here is what i have achieved, a sample code to generate full database table create sql.

    DerbyPlatform dp = new DerbyPlatform();
    dp.setDelimitedIdentifierModeOn(true);
    Database dbs = new Database();
    DerbyModelReader dmr = new DerbyModelReader(dp);
    Database test = dmr.getDatabase(conn, "MyDBTest");
    
    DerbyBuilder db = new DerbyBuilder(dp);
    String testSqlDerby = dp.getCreateTablesSql(test, true, true);
    System.out.println(testSqlDerby);
    
    System.out.println("\n\n\n\n");
    
    MySql50Platform mp = new MySql50Platform();
    mp.setDelimitedIdentifierModeOn(true);
    MySqlBuilder mb = new MySqlBuilder(mp);
    String testSqlMysql = mp.getCreateTablesSql(test, true, true);
    System.out.println(testSqlMysql);
    
    0 讨论(0)
  • 2021-02-03 16:34

    I'm not aware of JDBC having a generic facility to do this. You probably have to make a utility library that generates the SQL for table creation.

    Start with one that does ANSI SQL and test it on as many platforms as you intend to support. Remember, Java is still write-once, debug everywhere so you will need to test this on any platform you intend to support the system on. Subclass the generator if you have to make dialectic variations of the create statement for any of your platforms.

    0 讨论(0)
提交回复
热议问题