Skip to content

Implement Phase 2: Database migrations and chat schema - #14

Merged
DaveAlessi merged 1 commit into
mainfrom
sny-64-phase-2-data-model-migrations
May 5, 2026
Merged

Implement Phase 2: Database migrations and chat schema#14
DaveAlessi merged 1 commit into
mainfrom
sny-64-phase-2-data-model-migrations

Conversation

@DaveAlessi

Copy link
Copy Markdown
Owner

Add custom migration system and chat persistence tables:

Migration Infrastructure (SNY-45):

  • Created migration runner with transaction support and rollback
  • Migration tracking via schema_migrations table
  • CLI tools: npm run migrate, npm run migrate:status
  • Added allAsync() helper to dbHelpers for multi-row queries
  • Made createApp() async to support migration runner
  • Migrations are idempotent and work with :memory: databases

Schema Migrations:

  • 001_baseline.js - Captures current users table schema
  • 002_chat_tables.js - Adds conversations, conversation_members, messages tables
  • Foreign keys with CASCADE DELETE for referential integrity
  • Performance indexes on conversation_id, created_at, deleted_at, user_id
  • Soft delete support via deleted_at column in messages

Chat Repositories (SNY-48):

  • conversationRepository.js - 7 methods for conversation CRUD and membership
  • messageRepository.js - 7 methods for message CRUD with soft delete filtering
  • Follows existing userRepository pattern (async, db-first param, Promise-based)

Developer Tools (SNY-51):

  • seed.js script creates test users (alice, bob, charlie)
  • Generates sample conversations and messages for local testing
  • npm run seed:reset for clean test data

Database Schema:
Tables: users, conversations, conversation_members, messages, schema_migrations Indexes: 3 performance indexes for query optimization Total files: 9 created, 5 modified

All 59 tests passing. Zero breaking changes to existing functionality.

Add custom migration system and chat persistence tables:

**Migration Infrastructure (SNY-45):**
- Created migration runner with transaction support and rollback
- Migration tracking via schema_migrations table
- CLI tools: npm run migrate, npm run migrate:status
- Added allAsync() helper to dbHelpers for multi-row queries
- Made createApp() async to support migration runner
- Migrations are idempotent and work with :memory: databases

**Schema Migrations:**
- 001_baseline.js - Captures current users table schema
- 002_chat_tables.js - Adds conversations, conversation_members, messages tables
- Foreign keys with CASCADE DELETE for referential integrity
- Performance indexes on conversation_id, created_at, deleted_at, user_id
- Soft delete support via deleted_at column in messages

**Chat Repositories (SNY-48):**
- conversationRepository.js - 7 methods for conversation CRUD and membership
- messageRepository.js - 7 methods for message CRUD with soft delete filtering
- Follows existing userRepository pattern (async, db-first param, Promise-based)

**Developer Tools (SNY-51):**
- seed.js script creates test users (alice, bob, charlie)
- Generates sample conversations and messages for local testing
- npm run seed:reset for clean test data

**Database Schema:**
Tables: users, conversations, conversation_members, messages, schema_migrations
Indexes: 3 performance indexes for query optimization
Total files: 9 created, 5 modified

All 59 tests passing. Zero breaking changes to existing functionality.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented May 5, 2026

Copy link
Copy Markdown

@DaveAlessi
DaveAlessi merged commit 0ca58e1 into main May 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants