Skip to content

Work with EF migrations in Reserbiz

Roi Larrence Amatong edited this page Jul 29, 2021 · 1 revision

Overview

This page contains instructions how to work with EF migrations in Resebiz project. Reserbiz contains two datacontext classes, one is for ReserbizDeveloper and the other one is for dbReserbizSYSSQL database.

Work with EF migrations in ReserbizDeveloper database

  1. ReserbizDeveloper uses the ReserbizClientDataContext class. This holds all Model Classes/Tables belongs to ReserbizDeveloper database.
  2. If there are any changes made on any model classes that belongs to ReserbizDeveloper, we have to create a migration file for the modifications. Open terminal window and navigate to ReserbizAPP.LIB project and perform migration and to be table to do this, run the cli command below. But before running the cli command, make sure that ActivateEFMigration property inside appSettings.json file is set to true.
cd .\ReserbizAPP.LIB\
dotnet ef migrations add [Provide meaningful description for the migration] -c ReserbizClientDataContext -s ..\ReserbizAPP.API\
  1. After running the cli command above, this will create a migration file on D:\Projects\ReSerBiz\ReserbizAPP.LIB\Migrations\ReserbizClientData. Open the migration file, do some review and make some adjustments if needed before applying the changes on the database.
  2. If everything looks fine, then we apply the migration on the database. To do this, simply run the cli command below.
dotnet ef database update -c ReserbizClientDataContext -s ..\ReserbizAPP.API\
  1. Check the ReserbizDeveloper database if the changes were successfully applied.
  2. Set the ActivateEFMigration property inside appSettings.json file back to false.
  3. Any updates applied to ReserbizDeveloper database should be applied on other instances of this database as well to make sure everything is synced. Open the Postman application, open the Reserbiz Application/Client Db Manager/Sync All Databases request tab. Make sure that the request URL pointing to the local server. Click the Send button.

Work with EF migrations in dbReserbizSYSSQL database

  1. dbReserbizSYSSQL database uses the ReserbizDataContext class. This holds all Model Classes/Tables belongs to dbReserbizSYSSQL database.
  2. If there are any changes made on any model classes that belongs to dbReserbizSYSSQL, we have to create a migration file for the modifications. Open terminal window and navigate to ReserbizAPP.LIB project and perform migration and to be table to do this, run the cli command below.
cd .\ReserbizAPP.LIB\
dotnet ef migrations add [Provide meaningful description for the migration] -c ReserbizDataContext -s ..\ReserbizAPP.API\
  1. After running the cli command above, this will create a migration file on D:\Projects\ReSerBiz\ReserbizAPP.LIB\Migrations. Open the migration file, do some review and make some adjustments if needed before applying the changes on the database.
  2. If everything looks fine, then we apply the migration on the database. To do this, simply run the cli command below.
dotnet ef database update -c ReserbizClientContext -s ..\ReserbizAPP.API\
  1. Check the dbReserbizSYSSQL database if the changes were successfully applied.