Performing a database migration

Let's now try a database migration by carrying out the following steps:

  1. The database that we are working with already contains the tables and stored procedures in our scripts, so we are going to be brave and delete our database. In SSMS, in Object Explorer, right-click the database and choose Delete:

  1. We are going to create the database again with the same name. So, in Object Explorer, right-click on Databases and click on the New Database... option. Enter QandA for the name of the database and click OK:

  1. Back in Visual Studio, press F5 to run the app.
  2. After the app has run up, go to SSMS, and in Object Explorer, we'll see that the tables and stored procedures have been created. We'll also see a table called SchemaVersions:

  1. Right-click on dbo.SchemaVersions and choose Edit Top 200 Rows:

 

This is a table that DbUp uses to manage what scripts have been executed. So, we'll see our two scripts listed in this table.

  1. Back in Visual Studio, stop the app by pressing Shift + F5.
  2. Run the app again. The app will run up just fine.
  3. Inspect the database objects in Object Explorer in SSMS. The objects will be unchanged.
  4. Examine the contents of the SchemaVersions table. We'll find that no new scripts have been added.
  5. We can now stop the app again in Visual Studio.

So, our project is now set up to handle database migrations. All we need to do is to add the necessary SQL Script files in the SQLScripts folder remembering to embed them as a resource. DbUp will then do the migration when the app next runs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.167.151