db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Devaney" <bdeva...@docfinity.com>
Subject RE: Preventing tables from being dropped
Date Tue, 31 Jul 2007 12:32:14 GMT
There is a feature request for this.  See:
https://issues.apache.org/jira/browse/DDLUTILS-176

I wanted to avoid dropping tables that were not in the model and
truncating columns that were shorter in the model than they were in the
database being modified.  There is a patch that I wrote and included
with the issue.  It is a simple fix, but it has not gone through
testing, the apache developers or any other review, so use with caution.

-----Original Message-----
From: callme_sanjay [mailto:callme_sanjay@yahoo.com] 
Sent: Tuesday, July 31, 2007 8:11 AM
To: ddlutils-user@db.apache.org
Subject: Re: Preventing tables from being dropped


Hello All,

I am facing similar problem , 

Want to update the database but do not want to touch the other tables 

Tried the solution mentioned in the "thread" but it;s not working ..

Do I need to any other care while doing it.

Please reply 

Regards
-Sanjay


Guido Schreuder-2 wrote:
> 
> Hi Tom,
> 
> Yep, that'll work, i was thinking along the same line already
> 
> thanks,
> Guido
> 
> On Sat, 2007-04-14 at 16:58 -0700, Thomas Dudziak wrote:
>> Hi Guido
>> 
>> On 4/12/07, Guido Schreuder <g.schreuder@xs4all.nl> wrote:
>> > I am looking for a way to prevent tables from being dropped when
>> > executing Platform.alterTables(Database, boolean)
>> >
>> > The reason for this is that my model is iteratively constructed
without
>> > prior knowledge of the final model. Currently this will lead to
>> > "unknown" tables being dropped, causing data to be lost.
>> >
>> > An option like would be welcome, but maybe being able to somehow
>> > decorate the SqlBuilder and/or ModelComparator might yield a more
>> > flexible solution. Although the latter would probably not be
trivial.
>> 
>> Unfortunately, you can't at the moment, at least not out of the box
>> (but a feature request in JIRA would be appreciated).
>> However, you might be able to achieve what you want by using a
>> modified version of e.g. the
>> PlatformImplBase#getAlterTablesSql(Connection, String, String,
>> String[], Database, CreationParameters) method. More precisely, if
you
>> do the following:
>> 
>> String   sql          = null;
>> Database currentModel = readModelFromDatabase(connection,
>> desiredModel.getName(), catalog, schema, tableTypes);
>> 
>> // Filter the read model here so that only relevant tables are in the
>> currentModel
>> 
>> try
>> {
>>     StringWriter buffer = new StringWriter();
>> 
>>     getSqlBuilder().setWriter(buffer);
>>     getSqlBuilder().alterDatabase(currentModel, desiredModel,
params);
>>     sql = buffer.toString();
>> }
>> catch (IOException ex)
>> {
>>     // won't happen because we're using a string writer
>> }
>> return sql;
>> 
>> 
>> The alterTables is nothing more than a wrapper around
getAlterTablesSql:
>> 
>> Connection connection = borrowConnection();
>> 
>> try
>> {
>>     return getAlterTablesSql(...);
>> }
>> finally
>> {
>>     returnConnection(connection);
>> }
>> 
>> hope that helps,
>> Tom
>> 
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Preventing-tables-from-being-dropped-tf3567482.htm
l#a11922873
Sent from the Apache DdlUtils - User mailing list archive at Nabble.com.


Mime
View raw message