chucknorris / roundhouse

RoundhousE is a Database Migration Utility for .NET using sql files and versioning based on source control
http://projectroundhouse.org
917 stars 249 forks source link

[Enhancement] Run external tasks after database creation #38

Open k4gdw opened 12 years ago

k4gdw commented 12 years ago

Is there a way to run an external task, such as aspnet_regsql.exe on a database after it's created? Here's my scenario. We have several systems that have a table that has a foreign key into the aspnet_Users table. Provisioning a new instance would be a little less error prone if there was a way to have RoundhousE create the database, run aspnet_regsql.exe on it, then start creating our tables.

ferventcoder commented 12 years ago

We can set up a hook in model so that at certain points RH can run processes.

ferventcoder commented 12 years ago

One thing to consider is how this works across multiple machines and how it would work with silent.

k4gdw commented 12 years ago

Perhaps adding element to _BuildInfo.xml or, even better, define several convention based folders to hold .bat or even .ps1, files to execute hooks at various points in the process? For my scenario, a folder something like alwaysRunAfterCreate could hold a .bat file to call aspnet_regsql.exe (with or without command line parameters). RH could then do a call-and-wait on whatever it finds in that folder (in order by file name like it does with up scripts). A similar folder, alwaysRunBeforeDoingAnything, could be used to hook in things like performing a database backup before starting a migration.

With aspnet_regsql.exe, the default is to actually bring up a gui where you configure everything. It also supports a plethora of command-line arguments. However, I don't think it has a silent option. In the *nix world, one can silently run programs that do not have a built-in silent option by routing the output to /dev/null. Is there a Windows equivalent? That might be a way to handle hooks in silent mode.

With regard to multiple machines, I suppose there would simply have to be a requirement for whatever exe was being hooked in to support connecting to a remote box. Otherwise it would only work on the local machine.

ferventcoder commented 12 years ago

I actually implemented the membership as a single sql file. I found what it actually calls and made it work. That doesn't translate very well when there are changes/updates to the membership stuff, but it could technically provide a workaround for a moment.

ferventcoder commented 12 years ago

I am pretty sure there is a silent portion to the command. In fact I believe I have used it in the past...

In windows, it is up to the developer of the tool to allow for silent and there is no single standard. :(

ferventcoder commented 12 years ago

I'd like to explore the folders concept. That is actually a pretty interesting way of adding the feature. What if you dropped the executable in the folder as well to ensure it worked? How would you make decisions on what to run? Is it that RH only runs .bat files in order of names?

k4gdw commented 12 years ago

Running in order of names would only really be necessary if more than one task needed to be run and they had to be run in a specific order. As far as deciding what to run, that could be convention based. If it's an alwaysRun folder, anything in there gets run every time, in file name order in the case of multiple files. If it's a runOnce folder, RH could keep track of those just like it does the up scripts by inserting records into the ScriptsRun table. It really doesn't have to just be bat files. I'm not certain about copying the exe into the folder and running it directly though. That might complicate passing command-line parameters . It might also preclude using the file name to determine execution order of multiple files.

k4gdw commented 12 years ago

One of the answers to this StackOverFlow question suggested appending >NUL 2>NUL to the end of a command to force it to be silent. http://stackoverflow.com/questions/411247/running-a-cmd-or-bat-in-silent-mode To test this, I created this testSilent.bat file:

@echo off dir

Obviously, if I execute it without >NUL 2>NUL it gives a directory listing. calling testSilent.bat >NUL 2>NUL just returns me to the command prompt. So, theoretically, RH could use that same technique to force silent execution even if the hook didn't provide a silent option.

ferventcoder commented 12 years ago

Silent meaning never asking for input, not in having no output. Wouldn't you want RH to be returning the output so you would know that the item failed or succeeded and what it had to say?

k4gdw commented 12 years ago

Oh yes, I can't think of any time I'd want silent output from RH. However, I don't know that I'd always want the screen filled up with output from external tools unless it failed. As far as input, it really isn't silent because it gets it's instructions on what to do from somewhere, even it it's only looking at the conventional folders for scripts to run.

The reason I was thinking .bat (.cmd, .ps1 or even .vbs for that matter) for the hooks is it would allow the user to easily pass any required parameters to whatever executable they need to call. The configuration for that external tool would be right there where it's used and not in some configuration file located elsewhere. I don't see a problem with it being able to run .exe's directly if they don't need any arguments.

Bryan Johns K4GDW http://www.greendragonweb.com

Do not meddle in the affairs of dragons, for you are crunchy and taste good with ketchup.

On Fri, Dec 9, 2011 at 3:56 PM, Rob Reynolds < reply@reply.github.com

wrote:

Silent meaning never asking for input, not in having no output. Wouldn't you want RH to be returning the output so you would know that the item failed or succeeded and what it had to say?


Reply to this email directly or view it on GitHub: https://github.com/chucknorris/roundhouse/issues/38#issuecomment-3086565

mpareja commented 12 years ago

This would be pretty useful to me - especially if combined with my workflow branch. That said, we'd start stepping into the boundaries of other deployment tools...