-
Run Docker container
The following command will pull MSSQL image (if not present) and run container based on it:
- Linux:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=RoomMe22" \
-p 1433:1433 --name RoomMeDb -h RoomMeDb \
-d mcr.microsoft.com/mssql/server:2019-latest
- Windows:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=RoomMe22" -p 1433:1433 --name RoomMeDb -h RoomMeDb -d mcr.microsoft.com/mssql/server:2019-latest
-
Go to sqlcmd in Docker container
First, run interactive bash of the container.
- Linux:
sudo docker exec -it RoomMeDb "bash"
- Windows:
docker exec -it RoomMeDb "bash"
- Then run this:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "RoomMe22"
You should see in your terminal new line started with 1>
- Create database
CREATE DATABASE RoomMeDb
GO
- That's all, now you can connect to your database.
- When you shut down created container, you can run it through Docker Desktop or using following command:
docker start RoomMeDb
- Type in your shell
dotnet tool install --global dotnet-ef
We want to work always with as fresh DB changes as possible:
- After you prepared your database open Backend solution in Visual Studio 2019
- Open Package Manager Console and type
update-database
to update your database to current iteration
- After you made some changes in DB (e.g created new table) you should create new migration
- Open Package Manager Console and type
add-migration <<name>>
where <<name>> should be replaced with the name of migration (e.g add-migration create_users_table)
- Verify whether the migration contains only changes that it should have (check new created file in
migrationsfolder) - If step above is positive, update your database using
update-databasethen commit your changes - If step 3. was negative, then revert your changes using
remove-migration
and try to fix changes, then repeat whole proccess