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

Expose Table.IfExists in the fluent API #62

Open
loona70 opened this issue Feb 18, 2016 · 1 comment
Open

Expose Table.IfExists in the fluent API #62

loona70 opened this issue Feb 18, 2016 · 1 comment
Labels

Comments

@loona70
Copy link

loona70 commented Feb 18, 2016

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
Copy link
Owner

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.

@dradovic dradovic changed the title Can I check existence of a table without dropping it Expose Table.IfExists in the fluent API Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants