Skip to content

Database

Schema

The blacklake server uses PostgreSQL to store metadata about repositories, commits, and objects.

Tables

repositories

Stores repository information.

Column Type Description
id integer Primary key
name varchar(255) Unique repository name
description text Optional description
created_at timestamp Creation time
updated_at timestamp Last update time

commits

Stores commit information.

Column Type Description
id integer Primary key
sha varchar(64) Unique commit SHA
message text Commit message
author varchar(255) Commit author
repository_id integer Foreign key to repositories
parent_sha varchar(64) Parent commit SHA
created_at timestamp Creation time

objects

Stores object (file/blob) information.

Column Type Description
id integer Primary key
sha varchar(64) Object SHA
path varchar(1024) File path
object_type varchar(20) Object type (blob, tree)
size integer Object size in bytes
commit_id integer Foreign key to commits
s3_key varchar(1024) S3 storage key
created_at timestamp Creation time

Migrations

Database migrations are managed using Alembic.

Initialize Database

# Create initial migration
alembic revision --autogenerate -m "Initial schema"

# Apply migrations
alembic upgrade head

Create Migration

alembic revision --autogenerate -m "Description of changes"

Apply Migrations

# Upgrade to latest
alembic upgrade head

# Downgrade one version
alembic downgrade -1

# View migration history
alembic history

Connection String

The database connection string is generated from configuration:

postgresql://username:password@host:port/database

Docker Setup

When using Docker Compose, the database is automatically initialized with:

  • Database: blacklake
  • Username: blacklake
  • Password: blacklake
  • Port: 5432

Backup and Restore

Backup

pg_dump -h localhost -U blacklake blacklake > backup.sql

Restore

psql -h localhost -U blacklake blacklake < backup.sql