There are two basic ways to run Postgres locally:
Most people run Postgres natively without Docker as it's simpler, runs all the time in the background, and because Docker uses extra resources.
There are two very popular options.
brew install postgresql
brew services start postgresql
And that's it!
And then you are good to go!
The easiest way is to download and run the installer from the Postgres website.
docker-compose.yml
file inside the root of your project with
the following contentversion: "3.7"
services:
db:
image: postgres:latest
volumes:
- data:/var/lib/postgresql/data
env_file: ./.env.local #Here we are using the already existing .env.local file
ports:
- "5432:5432"
db-test:
image: postgres:latest
env_file: ./.env.test.local
ports:
- 5433:5432
volumes:
data:
.env.local
file add 3 new environment variables which are
required by dockerPOSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=your_database_name
Given these values, update DATABASE_URL
in .env.local
to something
similar like
postgresql://your_user:your_password@localhost:5432/your_database_name
and in .env.test.local
to
postgresql://your_user:your_password@localhost:5433/your_database_name
Please note that test database is using port 5433
instead of 5432
package.json
to start the database before Blitz"scripts": {
"predev": "docker-compose up -d",
"dev": "blitz dev",
}
docker-compose up -d
and
blitz prisma migrate dev
.