-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: hbm2dd code change to generate outputfile for deltas anyone?
PostPosted: Mon Nov 20, 2006 11:26 am 
Newbie

Joined: Tue May 02, 2006 12:32 pm
Posts: 8
When using Hibernate tools 3.2.0.beta8 to determine the database deltas using the update="true" option for hbm2ddl task, I am finding that the DDL is executed correctly and echoed to the screen, but is not saved in the outputfilename="schema_alter.sql".

I have had a look at the Code and it looks like currently there is no support for writing the deltas to a file.

Would any of the developers be kind enough to add this support ? it has also been requested on another thread. I think the code changes are very small :-

Hbm2DDLExporterTask

Code:
public void execute() {
      if(schemaUpdate) {
         SchemaUpdate update = new SchemaUpdate(parent.getConfiguration() );
         update.execute(scriptToConsole, exportToDatabase);         
      }
      else {
         SchemaExport export = new SchemaExport(parent.getConfiguration() );
         if(outputfileName!=null) {
            export.setOutputFile(new File(getDestdir(),outputfileName).toString() );
         }
         if(delimiter!=null) {
            export.setDelimiter(delimiter);
         }


add a :-

update.setOutputFile(new File(getDestdir(),outputfileName).toString() );

to the first part of 'if' above and corresponding settor in SchemaUpdate, just like there is on the 'else' and SchemaExport.java , then

in the execute() of SchemaUpdate.java

Code:
String[] createSQL = configuration.generateSchemaUpdateScript( dialect, meta );
         for ( int j = 0; j < createSQL.length; j++ ) {

            final String sql = createSQL[j];
            try {
               if ( script ) {
                  System.out.println( sql );
               }
               if ( doUpdate ) {
                  log.debug( sql );
                  stmt.executeUpdate( sql );
               }
            }
            catch ( SQLException e ) {
               exceptions.add( e );
               log.error( "Unsuccessful: " + sql );
               log.error( e.getMessage() );
            }
         }


I guess we need some of the code like in the SchemaExport.java's to write formatted statements to a file writer.

Code:
String formatted = format( sql );
      if ( delimiter != null ) {
         formatted += delimiter;
      }
      if ( script ) {
         System.out.println( formatted );
      }
      log.debug( formatted );
      if ( outputFile != null ) {
         fileOutput.write( formatted + "\n" );
      }


If anyone could do this, it would be very much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
submit a patch to our jira with the changes and i will look at it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 6:17 am 
Beginner
Beginner

Joined: Tue Mar 21, 2006 5:49 pm
Posts: 20
Was this ever added to jira and/or implemented?

BTJ

_________________
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
maybe it's in there, but can't recall the issue number.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 8:16 am 
Newbie

Joined: Tue May 02, 2006 12:32 pm
Posts: 8
I never actually raised this as a JIRA, as we went with another solution : we found that although the hbm2ddl update='true' task detected most schema changes i.e. new columns and new tables etc, it did not detect more subtle changes (from memory I think these were things like a new index from a @index annotation and maybe even nullability changes).

We needed a solution that detects all schema changes however minor, so we now get hbm2ddl task to generate a new DB schema DDL with the update='false' (this is the 'required' DB schema), then we use Navicat MySql tool which will do a database Stucture Synchronisation between the 'required' DB and our currently 'live' DB schema. The tool produces the alter DDL statements to change the 'live' schema to match the 'required' target structure. We run the alter statements as part of our build.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.