Embedding SQL Scripts in our project

In the last subsection, we told DbUp to look for SQL Scripts that have been embedded in our project. So, we are now going to embed SQL Scripts for the tables and stored procedures in our project so that DbUp will execute them if they haven't already been executed when our app loads:

  1. In Solution Explorer, right-click on the project, and choose Add | New Folder. Enter SQLScripts as the folder name.
  2. Right-click on the SQLScripts folder and choose Add New Item....
  3. In the dialog box that appears, select the General tab and then Text File and enter 01-Tables.sql as the filename:

  1. Copy the contents of the script from https://github.com/PacktPublishing/ASP.NET-Core-3-and-React-17/blob/master/Chapter07/backend/SQLScripts/01-Tables.sql and paste it into the file we just created.
  2. Right-click on 01-Tables.sql in Solution Explorer and choose Properties to view the properties of this file.
  3. Change the Build Action property to Embedded resource:

This embeds the SQL Script in our project so that DbUp can find it.

  1. Let's repeat this process for the stored procedures by first creating a file called 02-Sprocs.sql in the SQLScripts folder with the content from https://github.com/PacktPublishing/ASP.NET-Core-3-and-React-17/blob/master/Chapter07/backend/SQLScripts/02-Sprocs.sql. Let's not forget to embed this file as a project resource.
DbUp will run SQL Scripts in name order, so it's important to have a script naming convention that caters to this. In our example, we are prefixing the script name with a two-digit number.

So, those are the SQL Scripts that make up our database saved within our project.

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

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