Switching to Production Database
In this lesson, we're going to switch from sqlite to a production database
Switching to production database#
Till now, we were using sqlite and it was perfectly fine. However, when it comes to production level application, we need to set up a database which is built for handling a large amount of data. Since we are using Entity framework, we can use almost any relational database such as mysql or postgres. We can't use non-relational databases such as mongodb with Entity Framework. We have built our application with relational databases in mind so we have nothing to worry about.
We are going to use Postgres as our choice of production database. One of the main advantages of using Postgres is that we don't need a credit card to use this on the internet. Let's start by installing postgres in our computer.
For using Postgres or any database, it's much easier to go with Docker rather than installing it separately. So go to docker.com/products/docker-desktop, and download it as per your operating system. Running database with docker will create it in a separate container which makes it much easier to operate because we are not running the database in our operating system but in a virtual machine.
After installing docker, open the terminal and type:
It will check our local machine for the postgres image. If it doesn't find one, it will download it on our behalf. After successful loading, it will give us the image of the container. We can see this running inside docker desktop. We can also see the logs of the running application if we wish to. We can see the credentials if we click on inspect. We can also see the port. On top, we have our port in our application. The bottom one is the docker port.
Let's configure our application to use Postgres instead of Sqlite. We need to open
appsettings.development.json file and change the default connection string.