HyperSaaS
BackendDatabase

Overview

Database configuration, migrations, and conventions.

HyperSaaS uses PostgreSQL 17 with the pgvector extension for vector similarity search. The database is configured with ATOMIC_REQUESTS = True, meaning each HTTP request is wrapped in a transaction.

Configuration

The database connection is configured via the DATABASE_URL environment variable using django-environ:

# config/settings/base.py
DATABASES["default"] = env.db("DATABASE_URL")
DATABASES["default"]["ATOMIC_REQUESTS"] = True
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

Docker Setup

The local Docker stack uses pgvector/pgvector:pg17:

# Connect to PostgreSQL
docker exec -it backend_local_postgres psql -U <user> -d backend

# Verify pgvector
SELECT extname, extversion FROM pg_extension WHERE extname = 'vector';

Local Setup (Without Docker)

# Create database
createdb hypersaas

# Enable pgvector extension
psql -d hypersaas -c "CREATE EXTENSION IF NOT EXISTS vector;"

# Run migrations
python manage.py migrate

Migrations

# Generate migrations after model changes
python manage.py makemigrations

# Apply migrations
python manage.py migrate

# Check for pending migrations
python manage.py makemigrations --check

Base Model

All models inherit from BaseModel in backend/core/models.py:

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True

This provides created_at and updated_at timestamps on every model.

On this page