Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow many assemblies to contribute IMigrations in the same migrations run #467

Merged
merged 10 commits into from Feb 27, 2015

Conversation

JulianRooze
Copy link

See: #463 for the original issue that I created.

In short: not all of our migrations are in the same assembly. This is deliberate as our application is very modular in nature and a module is able to define its own (very specific to its need) tables and other database objects, so migrations are present in several assemblies. Currently, it's only possible to do this through iterating through all your migration assemblies and creating a separate runner for each one, which doesn't necessarily run the migrations in the correct order.

I've made a change that preserves current functionality (you can still pass in a single Assembly instance to the runner) but adds the ability to also provide a IAssemblyCollection instance. The current overloads that accept a Assembly parameter default to creating a implementation of IAssemblyCollection, namely SingleAssembly.

I've tried to keep breaking changes to a minimum, but to preserve sensical naming I've had to rename properties that are part of the public API to "Assemblies" instead of "Assembly".

Julian Rooze and others added 4 commits January 10, 2014 03:26
…on, so I refactored how getting a embedded resource from an Assembly works when you pass in multiple assemblies to the Runner.
… used a singular name to plural (assembly -> assemblies)
Exposing @Julian Rooze multiple assemblies support to msbuild task.
@nfplee
Copy link

nfplee commented Feb 15, 2014

I've just had a chance to test this. I have a modular application and this seemed like a good idea. Each assembly/module has a class which implements IVersionTableMetaData. This allows me to have a separate set of migrations per assembly/module and the versions are managed per assembly in a separate version table (ideally this would be within the same table but you would need to store the assembly which run the migration and remove the unique constraint on the version).

However if I have a migration within each assembly with the same version number then it throws an error.

I know I can get around this by looping over each assembly and running the migrations per assembly but it's quite slow and also the transaction is managed per assembly so if one statement fails in an assembly then it doesn't prevent the remaining assemblies from trying to commit their changes.

@tommarien
Copy link
Contributor

@JulianRooze How does this work, it's just a runner change for programmatic access ?

@JulianRooze
Copy link
Author

@tommarien Yes, basically, that's how the change is exposed to the outside. We use a console application as our migration runner that scans all loaded assemblies for IMigration implementations and feeds those assemblies to the standard MigrationRunner, which now also accepts a IAssemblyCollection.

Internally, places that previously accepted an Assembly instance now accept a IAssemblyCollection which is then used to aggregate all migrations from all those assemblies into a single feed. The only two things that were ever accessed on Assembly were GetExportedTypes (to find the implementations of IMigration) and GetManifestResourceNames (for accessing assembly embedded SQL scripts) which have been exposed on the IAssemblyCollection as well.

@tommarien
Copy link
Contributor

@JulianRooze i would consider merging it in if the code was 100% backwards compatible

What i mean is that for instance the msbuild runner should have both options still open : old style 1 assembly and new multiple assemblies for instance

Any chance you can create a branch from our source and reincorperate the changes in a backwards compatible way ?

@JulianRooze
Copy link
Author

The MsBuild changes were a contribution by @esakal. I'll take a look if I can make that backwards compatible.

How do you suggest I approach keeping the naming backwards compatible while keeping them sensical? I did a lot of renaming in 28d02b8 because naming something typed IAssemblyCollection with a singular name like "Assembly" doesn't make a lot of sense, so I pluralized those to "Assemblies".

I suppose I could expose both a property of type Assembly called "Assembly" and a property of type IAssemblyCollection called "Assemblies". Would that be okay? And how would that Assembly property behave when the migration uses multiple assemblies? Throw an exception, return the first assembly?

@tommarien
Copy link
Contributor

@JulianRooze i just quickly checked the change by esekal, it already looks backward compatible, i guess all should be fine

@JulianRooze
Copy link
Author

Okay, thanks for the check. Let me know if you need me to make any changes to make this mergeable.

@tommarien tommarien added feature A new feature (we all like those) improvement Improvement of behavior or code quality labels Feb 17, 2015
@tommarien tommarien added this to the vNext milestone Feb 17, 2015
@tommarien tommarien merged commit 8851f2f into fluentmigrator:master Feb 27, 2015
tommarien added a commit that referenced this pull request Feb 27, 2015
  Build error fixes after merge
  msbuild multiple assemblies support
  Renamed every variable/parameter/property of IAssemblyCollection that used a singular name to plural (assembly -> assemblies)
  Using Assembly.GetCallingAssembly() proved to not be a working solution, so I refactored how getting a embedded resource from an Assembly works when you pass in multiple assemblies to the Runner.
  Refactored the dependency on a single Assembly for the Runner into (potentially) many Assembly instances.

Conflicts:
	src/FluentMigrator.Runner/MaintenanceLoader.cs
@tommarien
Copy link
Contributor

@JulianRooze Thanks Julian, seems to run fine ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature (we all like those) improvement Improvement of behavior or code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants