db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Igor Markovic" <igor-l...@izecom.com>
Subject Adding sequences on model change
Date Fri, 24 Nov 2006 10:21:45 GMT
Hi,

Here my first post on this list :)

I noticed that when I do a database model change by doing:

        DataSource oldDataSource = testDdlUtils.getDataSource(
                "org.postgresql.Driver", "jdbc:postgresql://localhost/test1", "test", "test");

        DataSource newDataSource = testDdlUtils.getDataSource(
                "org.postgresql.Driver", "jdbc:postgresql://localhost/test2", "test", "test");
        
        Platform oldPlatform = PlatformFactory.createNewPlatformInstance(oldDataSource);
        Platform newPlatform = PlatformFactory.createNewPlatformInstance(newDataSource);

        Database newDatabaseModel = newPlatform.readModelFromDatabase("databaseNewModel");

        oldPlatform.alterTables(newDatabaseModel, false);        

that the sequences aren't created, but when I do a createTables (or getCreateTablesSql) they
are. I looked into the code and saw that on creation in the PostgresSqlBuilder the sequences
are created when a table query is build, but there was no code to do this when the database
model was altered and a new table was created in this proces. So I added the following code
and it seems to work:

    /**
     * Processes the addition of a table with auto increment columns.
     * 
     * @param currentModel The current database schema
     * @param desiredModel The desired database schema
     * @param params       The parameters used in the creation of new tables. Note that for
existing
     *                     tables, the parameters won't be applied
     * @param change       The change object
     */
    protected void processChange(
                Database           currentModel,
                Database           desiredModel,
                CreationParameters params,
                AddTableChange     change) throws IOException
    {
        Table table = change.getNewTable();

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);

            if (column.isAutoIncrement())
            {
                createAutoIncrementSequence(table, column);
            }
        }
        super.processChange(currentModel, desiredModel, params, change);        
    }

I hope someone can look at this and see if this can be used. It should ofcourse also be implemented
for other database types than PostgreSQL.

Regards,

Igor
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message