I'm trying to migrate my db based on my data in my current db. I'm having a hard time querying the db to grab information to allow me to do this. My ideal solution would look something like
public partial class Reset: DbMigration
{
public override void Up()
{
string SqlCmd = "my query";
if(Execute(SqlCmd) > 5)
{
//do this migration
}
}
}
So I'm having problem getting data back in the migration.
Edit
Many of you guys have been wondering why I need to do this, so I'll give you guys the nasty details.
So as our project have grown, so did our db migration history. We have over 200 rows in our migration history table. We split the db up and did some maintenance here and there to the point that running all the migrations from scratch with an empty db would result in an error because some tables weren't created yet. Yes its a huge mess and that's why I wanted to clean it up. I ran into this post on SO to reset the migrations to a clean slate. I didn't use the accepted answer because the migration mess we have wouldn't allow it to work. So the second highest answer was used. The only problem with this chosen solution was that for every developer in your team, you'd have to point them to the instructions to update their db or have them download the latest one. They're not able to do
update-database
cleanly. So to allow them to update cleanly and make it hassle free for everyone, I'd like to query the migration history table, see if its the mess and if so delete all the history and skip the actual migration, but still populate the migration row in the table.