Skip to content
You are reading the HappyView v2 docs, which are no longer updated. Read the v3 docs.

Database Setup

HappyView supports two database backends: SQLite (default) and PostgreSQL. The backend is auto-detected from your DATABASE_URL scheme, or you can set DATABASE_BACKEND explicitly.

SQLite requires zero setup. HappyView creates the database file automatically on first startup.

Terminal window
DATABASE_URL=sqlite://data/happyview.db?mode=rwc

The ?mode=rwc parameter tells SQLite to create the file if it does not exist. The path is relative to the working directory (or use an absolute path).

When to use SQLite:

  • Getting started or local development
  • Small to medium deployments
  • Single-server setups where simplicity is preferred

For larger deployments or when you need concurrent write scalability, use Postgres.

Terminal window
DATABASE_URL=postgres://happyview:happyview@localhost/happyview

You need to create the database before starting HappyView:

Terminal window
createdb happyview

HappyView runs migrations automatically on startup for both backends.

When to use Postgres:

  • High write concurrency from many simultaneous users
  • You need Postgres-specific features (e.g., advanced JSON queries in Lua scripts)
  • You already have a Postgres infrastructure
VariableDescription
DATABASE_URLConnection string. sqlite://... for SQLite, postgres://... for Postgres
DATABASE_BACKENDOptional. Force sqlite or postgres. Auto-detected from DATABASE_URL if not set

The default docker-compose.yml ships with the Postgres service commented out. To use Postgres:

  1. Uncomment the postgres service and pgdata volume in docker-compose.yml
  2. Uncomment the depends_on: postgres block in the happyview service
  3. Update DATABASE_URL in .env:
    Terminal window
    DATABASE_URL=postgres://happyview:happyview@postgres/happyview
  4. Set the Postgres credentials:
    Terminal window
    POSTGRES_USER=happyview
    POSTGRES_PASSWORD=happyview
    POSTGRES_DB=happyview

Both backends support the same Lua database API (db.query, db.get, db.count). Write SQL in SQLite syntax by default. If you are using Postgres, HappyView automatically translates common SQLite patterns to Postgres equivalents at runtime.

If you are migrating existing Lua scripts from Postgres SQL syntax to SQLite syntax, see the Postgres to SQLite migration guide.