db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Dudziak" <tom...@gmail.com>
Subject Re: Renaming columns
Date Fri, 12 Jan 2007 18:04:14 GMT
On 1/12/07, Christoffer Hammarström <kreiger@imcode.com> wrote:

> I'm trying to rename and change the type of some columns in MSSQL and
> MySQL databases.
> I have tables "templates", "text_docs", and "templates_cref".
> "templates" has primary key "template_id", which is referred by foreign
> keys "text_docs.template_id" and "templates_cref.template_id".
> What i want to do is to drop the "templates" table, and then rename the
> "template_id" column in "text_docs" and "templates_cref" to
> "template_name". Also, i want to change the "template_id" column and a
> couple of other columns from an integer column to a varchar(80) column,
> and taking their new values from the "simple_name" column corresponding
> to the "template_id" in the dropped "templates" table.
> I've found no easy way to accomplish this using the ddlutils API.
> I can't call column.setName(newColumnName), because that makes ddlutils
> think that the old column has been removed and a new column has been added.

The problem is that there are two database models, the current one in
the database, and the new, changed one, and the newer one contains
different columns from the older one. Now, DdlUtils has no way of
distinguish (via comparing these two models) that a column was renamed
vs. that one column was dropped and another added.
Adding support for this (which is essentially a refactoring) is tricky
because it needs a concept of tasks ('rename') which means a new API
and Ant tasks.

One thing that you could do for now is to export the data to XML, then
let DdlUtils drop and add the renamed column and then re-import the
data again.


View raw message