sougatamondal / migratordotnet

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

Create Migrator Classes from CommandLine #98

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
After using the migrator for a while i decided it could be much more usable if 
the developer 
should not worry to much about the creation of new integrations.

For this reason i added some abilities to the Migrator.Console.exe

1. Assemble the Migrator files on the fly.
Example: migrator.console.exe SqlServer "Data Source=.\SQLEXPRESS;Initial 
Catalog=MigratorSpike;Integrated Security=True; " -dir Modify
This will take all the .cs (CSharp support only) files from the Modify 
directory and apply them to 
the database

2. Use app.config instead of specifying the ConnectionString
Example: migrator.console.exe MigratorSpike -dir Modify
This will use the connection string from Migrator.Console.exe.config with the 
name 
"MigratorSpike"
Example Migrator.Console.exe.config:
<?xml version="1.0"?>
<configuration>
    <connectionStrings>
        <add name="MigratorSpike" connectionString="Data Source=.\SQLEXPRESS;Initial 
Catalog=MigratorSpike;Integrated Security=True;" 
providerName="System.Data.SqlServer" />
    </connectionStrings>
</configuration>

3. In my opinion the most useful feature: Generate new Migrations
Example: migrator.console.exe -generate SomeTableAddSomeColumn
This will generate a new class to a Modifiy directory with the given name, The 
migrator attribute 
comes prepopulated with the current Datestamp as a Long, The filename will also 
include the 
Datestamp for correct ordering. It will create the Modify directory if it 
doesn't exist yet.

Example 2: migrator.console.exe -generate SomeTableAddSomeColumn /ns:MyNamespace
If not specifying the /ns: switch all generated files will be generated with 
the default "Modify" 
namespace. If you want to change that specify the /ns: switch

Example 3: migrator.console.exe -generate SomeTableAddSomeColumn 
/ns:MyNamespace 
/outdir:C:\Source\MyProject\Database\Modify
If the /outdir: switch is not specified all files will be generated to the 
"Modify" subdirectory in the 
current working directory. When the switch is specified all files will be 
generated to the given 
directory.

Combine example 3 with a little DOS Magic and be able to run it from just one 
line:

create SomeTableAddSomeColumn
migrate

In the attached create.bat and migrate.bat wherein i check the outdir for 
existing files with the 
same classname, This prevents compilation errors. Another check could prevent 
the user to use 
C# keywords. One could even autmatically open the file in devenv.exe or even 
better run the 
generation from within Visual Studio and add the file to the project. Nice!

I didn't add UnitTests. It seems migrator.console project comes without them 
and i decided not 
to change it ;)

+ Oliver

P.S: There is a small constructor overload to the ScriptEngine, it allows to 
specify the trace 
attribute to prevent the output of Log messages when running from the console. 
I didn't create a 
separate patch for it. I hope it may be overseen. It's my first contribution so 
i will try to 
improve...

Original issue reported on code.google.com by Oliver.J...@gmail.com on 11 Mar 2009 at 3:39

Attachments: