On 11/24/06, Igor Markovic <[EMAIL PROTECTED]> wrote:

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.

Sounds like a bug. Could you please file a bug in JIRA ? and if
possible, could you attach the SQL for the old and new tables ?

thanks,
Tom

Reply via email to