dradovic / MigSharp

Mig# (MigSharp) is a .NET framework for database migrations and versioning
Other
106 stars 33 forks source link

Expose Table.IfExists in the fluent API #62

Open loona70 opened 8 years ago

loona70 commented 8 years ago

At this moment I can only check existence like this: schema.Alter(db => db.Tables["tabelname"].DropIfExists());

So it's always being dropped. But I want to check if it's there. If Not, create the table. This seems very obvious to me, so I assume I missed something.

Keep good work! Greeting from The Netherlands

dradovic commented 8 years ago

You didn't missing anything. For short: this feature does not exist yet.

When Mig# came into being, it was a pure migration fwk which assumed that a migration always know the state of the database it is migrating. So no "conditional API" was introduced. The whole fluent API only contains commands that execute something and do not return results. Later, we started using Mig# as a schema manipulating library (because a migration framework knows how to emit DDL) and DropIfExists was introduced.

So far, nobody asked for a IfExists. Actually, all providers already implement this functionality (as Mig# needs to know if the migration history table exists or not when being started). So that would make it easier to implement it. On the other hand, and IfExists that returns a boolean makes validation a bit more complicated. Because someone will evaluate this result and probably choose a different execution path of the migration logic depending on the outcome of the IfExists. So the validation logic would need to be extended to once let the migration run with IfExists yielding false and once with true to catch all execution paths. I hope this was not too complicated.

Long story short: I'm changing this issue into a feature request. Do you think you would be able to issue a PR for it? If not, I cannot promise if and when I'm going to tackle this.

As a workaround, you can use the db.Execute callback and do the check there.