Files
websitebuilder/DATABASE_SETUP.md
Kunthawat Greethong 4d1bb6892b
Some checks failed
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled
CI / e2e (push) Has been cancelled
CI / lint (push) Has been cancelled
Add websitebuilder app
2026-01-26 12:50:12 +07:00

2.4 KiB

Database Setup

Quick Start with Docker

The easiest way to set up the development database is using Docker Compose.

Prerequisites

  • Docker installed on your machine
  • Docker Compose installed

Start the Database Services

docker-compose up -d

This will start:

  • PostgreSQL 16 on port 5432
  • Redis 7 on port 6379

Stop the Database Services

docker-compose down

View Logs

docker-compose logs -f

Reset the Database

docker-compose down -v
docker-compose up -d

Manual PostgreSQL Setup

If you prefer to install PostgreSQL locally:

Install PostgreSQL

macOS (Homebrew):

brew install postgresql@16
brew services start postgresql@16

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install postgresql-16

Windows: Download and install from PostgreSQL Official Site

Create Database

# Connect to PostgreSQL
psql -U postgres

# Create database and user
CREATE DATABASE moreminimore;
CREATE USER moreminimore WITH PASSWORD 'moreminimore_password';
GRANT ALL PRIVILEGES ON DATABASE moreminimore TO moreminimore;
\q

Update .env.local

Create a .env.local file in the project root:

DATABASE_URL=postgresql://moreminimore:moreminimore_password@localhost:5432/moreminimore
REDIS_URL=redis://localhost:6379

Verify Connection

Run the following command to verify the database connection:

psql postgresql://moreminimore:moreminimore_password@localhost:5432/moreminimore -c "SELECT version();"

You should see the PostgreSQL version information.

Database Migrations

After setting up the database, run migrations:

npm run db:generate
npm run db:migrate

Troubleshooting

Port Already in Use

If port 5432 is already in use, you can change the port in docker-compose.yml:

ports:
  - '5433:5432' # Use 5433 instead

Then update your .env.local:

DATABASE_URL=postgresql://moreminimore:moreminimore_password@localhost:5433/moreminimore

Connection Refused

Make sure the PostgreSQL service is running:

docker-compose ps

If it's not running, start it:

docker-compose up -d

Reset Database

To completely reset the database:

docker-compose down -v
docker-compose up -d

This will delete all data and recreate the database from scratch.