Deployment & Migrations
Relevant source files
The following files were used as context for generating this wiki page:
The DRX CRM system utilizes a structured deployment pipeline and a version-controlled database migration strategy to ensure system stability, data integrity, and cross-platform synchronization. This system supports a privacy-first Next.js 16 application backed by Supabase (PostgreSQL), with deployment targets including Vercel for the frontend and Supabase CLI for database schema management.
Sources: README.md:3-8, README.md:144-148
Database Migration Strategy
Database changes are managed through incremental SQL migration files stored within the supabase/migrations and db/migrations directories. The project employs the Supabase CLI to handle local development resets and production pushes, ensuring that the schema remains consistent across environments.
Migration Lifecycle
The development workflow for schema changes involves creating new migration files, applying them locally to test, and then pushing them to the production instance.
The flow above illustrates the standard transition from a local schema change to a production update.
Sources: README.md:112-124, deploy-inventory-intake.sh:37-43
Key Migration Components
The core database structure is defined in a consolidated initialization script, establishing the fundamental multi-tenant architecture and security policies.
| Component | Description | Primary File Reference |
|---|---|---|
| Core Schema | Defines business_profile, inventory, sales, and customers. | supabase/migrations/20251128000000_init.sql |
| RBAC Schema | Implements app_permissions and role_permissions for granular access. | supabase/migrations/20251220000000_rbac_schema.sql |
| Inventory Intake | Introduces inventory_intakes and cost_history for tracking. | deploy-inventory-intake.sh:22-26 |
| Compliance Alignment | Adds cannabis-specific fields like thc_percentage and vendor tracking. | supabase/migrations/20260121000000_ensure_alignment.sql |
Sources: supabase/migrations/20251128000000_init.sql:10-185, deploy-inventory-intake.sh:22-28
Deployment Pipeline
Deployment is categorized into application hosting on Vercel and manual/automated script-based deployments for specific subsystems like the Inventory Intake or Help Center synchronization.
Vercel Deployment (Frontend/API)
The primary application is deployed via Vercel by connecting the repository and configuring environment variables. Migrations are automatically applied in the CI/CD pipeline.
Sources: README.md:144-153
Specialized Deployment Scripts
Certain features require localized deployment logic to handle specific pre-deployment checks and database validations.
- Inventory Intake Deployment (
deploy-inventory-intake.sh): A bash script that orchestrates the deployment of the cost tracking system. It follows a four-step process:- Apply Migration: Uses Supabase CLI or manual SQL application.
- Verify Schema: Manually confirms table existence.
- Build & Test: Runs
npm run buildto ensure code integrity. - Deployment Summary: Provides a checklist of what was updated (APIs, UI, AI Pricing).
Sources: deploy-inventory-intake.sh:7-96
This sequence ensures that the database is prepared before the application code is built and deployed.
Sources: deploy-inventory-intake.sh:20-80
Versioning and Release Management
Version management follows the Wrelik Brands Versioning Protocol, where a VERSION file at the repository root acts as the single source of truth.
Versioning Automation
The scripts/version.ts utility automates the process of analyzing the CHANGELOG.md to suggest and apply version bumps.
- Check Mode: Scans the
[Unreleased]section of the changelog to determine if amajor,minor, orpatchbump is required based on keywords like "Breaking", "Added", or "Fixed". - Bump Mode: Updates
VERSION,package.json,CHANGELOG.md, and multiple UI components (Sidebar, Footer, Admin page) to reflect the new version string.
Sources: scripts/version.ts:16-140, CHANGELOG.md:46-51
Pre-release Checklist
Before a deployment is finalized, the CHECKLIST_PRERELEASE.md must be satisfied:
- Versioning bumped in
package.jsonandVERSION. CHANGELOG.mdupdated in "Keep A Changelog" format.ENV_MATRIX.mdaligned with production secrets.- Database migrations successfully applied to staging/prod.
- Smoke tests passed for critical paths (Login, Checkout, Inventory).
Sources: CHECKLIST_PRERELEASE.md:3-12
Data Synchronization
Beyond schema migrations, the system handles data synchronization for external services like Featurebase via the scripts/sync-help-center.ts script.
Help Center Sync Logic
This script synchronizes local documentation defined in scripts/help-center-data.ts with the Featurebase API.
- Manage Collections: Fetches existing collections and creates new ones based on category tags (e.g.,
category:pos). - Upsert Articles: Compares local help articles with remote ones, performing a
POSTfor new articles or aPATCHfor existing ones.
Sources: scripts/sync-help-center.ts:86-155, scripts/help-center-data.ts:11-30
Summary
The deployment and migration framework in DRX CRM is designed for reliability through structured SQL migrations and automated versioning scripts. By strictly separating database schema updates from application builds and enforcing a rigorous pre-release checklist, the system maintains high availability and data consistency across its multi-tenant architecture.