You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by Igor Markovic <ig...@izecom.com> on 2006/11/24 11:21:45 UTC
Adding sequences on model change
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
Re: Adding sequences on model change
Posted by Thomas Dudziak <to...@gmail.com>.
On 11/24/06, Igor Markovic <ig...@izecom.com> 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