Published: 2018.02.17
Category: C#
DBUp
DBUp is a package which manages database updates. DBUpPT adds additional functionality to DBUp like creating the database and log table.
To use it please reference package with the package manager console
1 |
Install-Package DBUpPT |
Next create Console application and in the main add following code:
1 2 3 4 5 6 |
string serverName = "ServerName"; string dbName = "DatabaseName"; DBUp dBUp = new DBUp("gc"); Assembly assembly = Assembly.GetExecutingAssembly(); dBUp.PerformUpdate(serverName, dbName, assembly, false) |
Next add Scripts Folder and create inside sql scripts which you want to execute. In the properties of the script please select Embedded resource
When application will start, DBUpPT will:
- Check if database DatabaseName exists if not it will create it
- In the database it will create schema provided in the constructor “gc”
- It will start executing the scripts from the Script folder.