Red Gate forums :: View topic - Creating update scripts through Packager API
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

Creating update scripts through Packager API

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
AvonWyss



Joined: 29 Oct 2008
Posts: 30

PostPosted: Mon Nov 03, 2008 2:29 pm    Post subject: Creating update scripts through Packager API Reply with quote

I'm trying to write a small tool (to be used on our build server) which should create a migration script for two different versions of a database.

However, I would like to get the update scripts only; I'm not looking for a C# or EXE type project. Basically, I'm looking to get the same scripts one can review when using the UI during the packaging process.

Since the packaging API is quite small, I'm afraid that this functionality has not been exposed through the packaging API. So how can I do this? If the packaging API does not expose it, is there some Compare API and Data Compare API which can be used to achieve this?
Back to top
View user's profile Send private message
Michelle Taylor



Joined: 30 Oct 2006
Posts: 525
Location: Red Gate Software

PostPosted: Tue Nov 04, 2008 12:40 pm    Post subject: Reply with quote

The API should support outputting the update script - just set the OutputType to Script in the PackagerEngine constructor.
Back to top
View user's profile Send private message
AvonWyss



Joined: 29 Oct 2008
Posts: 30

PostPosted: Tue Nov 04, 2008 2:17 pm    Post subject: Re: Reply with quote

Michelle Taylor wrote:
The API should support outputting the update script - just set the OutputType to Script in the PackagerEngine constructor.

In the API V7.0, OutputType had only the values Executable and Project. Thank you for pointing out the Script option, which I now have tried to use. However, I found it odd that it still required the template directory to be valid (what are the C# templates for when only creating scripts?).

Anyways, I still do not get a script file... here's my code snippet I'm using for testing (only schema migration, no data):
Code:

using (Database oldScripts = new Database()) {
   Console.WriteLine("Reading old schema version scripts...");
   oldScripts.Register(Path.GetFullPath(commandLine.OldPath), scriptDatabaseInformation, options);
   using (Database newScripts = new Database()) {
      Console.WriteLine("Reading new schema version scripts...");
      newScripts.Register(Path.GetFullPath(commandLine.NewPath), scriptDatabaseInformation, options);
      Console.WriteLine("Finding differences...");
      Differences differences = oldScripts.CompareWith(newScripts, options);
      Work work = new Work();
      work.BuildFromDifferences(differences, commandLine.GetDatabaseOptions(), false, outputPaths);
      Console.WriteLine("Creating migration script...");
      using (PackagerEngine packager = new PackagerEngine(@"C:\Program Files\Red Gate\SQL Packager 6\SQL Packager Code Templates\C#\", Environment.CurrentDirectory, "test", work.ExecutionBlock, new ExecutionBlock(), OutputType.Script)) {
         packager.Package();
      }
   }
}
Back to top
View user's profile Send private message
Michelle Taylor



Joined: 30 Oct 2006
Posts: 525
Location: Red Gate Software

PostPosted: Tue Nov 04, 2008 8:05 pm    Post subject: Reply with quote

I'm investigating why the Script option isn't quite working at the moment - meanwhile, hopefully you can work around the problem by calling the command line from your code?

I'm sorry about the problem with the API.

BTW, your code seems to be missing a step - you need a line that looks a bit like:

Code:
work.GenerateSql(differences, null, Options.Default, false);


after your line which looks like:

Code:
work.BuildFromDifferences(differences, Options.Default, false,new WriteToFileOptions());


Last edited by Michelle Taylor on Wed Nov 05, 2008 2:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
AvonWyss



Joined: 29 Oct 2008
Posts: 30

PostPosted: Tue Nov 04, 2008 10:47 pm    Post subject: Re: Reply with quote

Michelle Taylor wrote:
meanwhile, hopefully you can work around the problem by calling the command line from your code?

My understanding is that the SQL Packager (non-API) can only be run against databases, and not against scripts.

Michelle Taylor wrote:
BTW, your code seems to be missing a step - you need a line that looks a bit like:

Thanks for the hint, I'll try that.
Back to top
View user's profile Send private message
AvonWyss



Joined: 29 Oct 2008
Posts: 30

PostPosted: Wed Nov 05, 2008 2:12 pm    Post subject: Re: Reply with quote

After adding the missin GenerateSql call, I now get an error message in a message box:
Code:
Output is not a Project or an Executable
Redgate.SQLPackager.Engine.PackagerException at d.b()

(I would have loved to attach a screenshot, but I cannot find the option to do so in this forum.)

Even worse, this message box is opened by the API, not by my code, which may make the application hang if run on a server without GUI (such as a buld server...) - that should certainly not happen in a non-visible API!

Can you please provide me a working sample to generate the SQL update scripts?
Back to top
View user's profile Send private message
acaterino



Joined: 12 Feb 2010
Posts: 3

PostPosted: Fri Nov 19, 2010 4:25 pm    Post subject: Is there a solution Reply with quote

I'm getting the same message that it is not a Project or Executeable.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group