minhphien / migratordotnet

Automatically exported from code.google.com/p/migratordotnet
0 stars 0 forks source link

Ability to dump migrations into .sql file #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm looking for a feature that will allow me to dump the migrations from a
certain schema version to the next into a .sql file that I can use to run
as part of an installer to upgrade the end-user db'es with the migrations
made during development.  

If possible, make it as easy as adding an additional property to the
Migrate MSBuild task that specifies the file to which to dump the
collective migrations that were executed.

Thanks
Carel 

Original issue reported on code.google.com by carel.l...@gmail.com on 17 Jun 2008 at 8:46

GoogleCodeExporter commented 9 years ago
I tried changing the status to an enhancement request, but was unsuccessful :(

Original comment by carel.l...@gmail.com on 17 Jun 2008 at 9:09

GoogleCodeExporter commented 9 years ago
I think this can be nice...anyway, if you need this now and cannot wait you can 
look 
at the console example and use the migrateup from there...i'm doing this when 
needing to upgrade as part of the execution and it works great...
You can also obviously record the migrations using the query trace tool of the 
RDBMS 
also and use this SQL for what you're looking for.

Until something like this is developed you have some workarounds.

Original comment by gustavo.ringel@gmail.com on 17 Jun 2008 at 9:54

GoogleCodeExporter commented 9 years ago
Hi

In case you interested, I took the opportunity this evening to add the feature 
in a
more transparent way.  I attach a patch file containing the feature in case you 
are
interested in harvesting the approach.  

I extended the ILogger interface and added a ApplyingDBChanges(string sql) 
method
that the TransformationProvider invokes when executing the SQL statements that 
change
the structure/content of the database (i.e. 
TransformationProvider.ExecuteNonQuery).
 I then used the Decorator pattern to add a SqlScriptFileLogger that decorates the
TaskLogger for both NAnt and MSBuild.  The decorater intercepts and basically
decorates the normal ApplyingDBChanges call by writing it to a file.  

I completed the feature by adding two additional properties to the NAnt/MSBuild 
task
called ScriptChanges and ScriptFile.  You can set ScriptChanges to indicate 
that the
sql statements should be scripted to the ScriptFile.

Regards
Carel

Btw, I only have VS 2008 installed on my PC and I had to upgrade the solution.  
I
therefore do not submit my .csproj file changes to make it easier to apply the 
patch
if you should wish to do so.  You will then however have to manually include the
SqlScriptFileLogger.cs file that I added to the Migration.MSBuild and 
Migrator.NAnt
projects.

Original comment by carel.l...@gmail.com on 18 Jun 2008 at 8:06

Attachments:

GoogleCodeExporter commented 9 years ago
Carel,
I'll take a look at the patch. Thanks.

Original comment by geoffl...@gmail.com on 19 Jun 2008 at 2:20

GoogleCodeExporter commented 9 years ago
Carel,
There's something funny with that patch. It's trying to patch 
SqlScriptFileLogger.cs
- but that file doesn't exist. The patch needs to create that file. Can you try 
and
recreate it?

Also it looks like there are 2 SqlScriptFileLoggers. One for NAnt and one for
MSBuild. Is it possible for that to be a shared class that just used the ILogger
interface?

Original comment by geoffl...@gmail.com on 19 Jun 2008 at 3:12

GoogleCodeExporter commented 9 years ago
Find attached another attempt at creating a patch.  This time I include 
everything so
beware that the .csproj have been upgraded to support VS 2008.

You are correct, there are 2 SqlScriptFileLoggers.  The one decorates the 
MSBuild
TaskLogger and the other one decorates the NAnt TaskLogger.  It should be 
possible to
make this a shared class, by letting it decorate an ILogger instance instead of 
the
individual NAnt/MSBuild task loggers.

Original comment by carel.l...@gmail.com on 19 Jun 2008 at 6:23

Attachments:

GoogleCodeExporter commented 9 years ago
Hi 

I changed the implementation and created a single SqlScriptFileLogger that is 
now
located in the Migrator.Framework.Loggers namespace.  It now decorates a ILogger
instance so it can be used in conjunction with any existing ILogger 
implementation.  

I also changed the NAnt/MSBuild TaskLogger and the 
Migrator.Framework.Loggers.Logger
implementation to issue a Trace statement for the ILogger.ApplyingDBChange 
method
call.  In this way the user will only see the output if he/she has selected to 
view
detailed output via setting the Trace flag or by requesting detailed output via
NAnt/MSbuild cmd line settings.

Find attached a patch for the changes.  Again, remember that the changes were 
made
with VS 2008 so be aware of changes to the .csproj and .sln files.

Original comment by carel.l...@gmail.com on 20 Jun 2008 at 6:12

Attachments:

GoogleCodeExporter commented 9 years ago
I could *really* use this.  Has it been included in the source yet?  Are there 
any
gotchas you're aware of?

Original comment by subdigi...@gmail.com on 5 Aug 2008 at 12:46

GoogleCodeExporter commented 9 years ago
SVN 110
Applied patch (with some minor changes)

Original comment by geoffl...@gmail.com on 5 Aug 2008 at 2:29