Skip to main content
The Database Schema Evolution

The Database Schema Evolution

Andrius LukminasAndrius LukminasDecember 28, 20254 min read354 views

Starting Point

The initial schema was simple: users, sessions, and a few core tables. As features grew, so did complexity.

Current Schema Highlights

Our schema now includes 50+ models covering:

  • Authentication - users, sessions, oauth_account_links, webauthn_credentials
  • Blog System - blog_posts, blog_categories, blog_tags, blog_comments
  • Project Management - projects, tasks, milestones, time_entries
  • Orders & Billing - orders, invoices, payments, subscriptions
  • System - error_logs, log_settings, webhooks, notifications

Migration Strategy

We use Prisma Migrate for schema changes:

# Development: Push changes directly
npx prisma db push

# Production: Create and apply migrations
npx prisma migrate dev --name add_log_settings
npx prisma migrate deploy

Lessons Learned

  • Add indexes early—retrofitting is harder
  • Use @db.Text for long strings, not VARCHAR
  • Foreign keys with onDelete: Cascade prevent orphans
  • Test migrations with production data copies

Related Articles

Comments

0/5000 characters

Comments from guests require moderation.