60abe8c76d
Replaces what would have been 42 individual in-flight migrations
(102→143 on feat/crm) with one consolidated migration that creates
every CRM table in its final shape — no ALTER chains. Coexists with
upstream's pre-existing 102-106 by filename suffix; the runner sorts
within same-number groups.
Tables consolidated:
- business_profile + business_bank_accounts (issuer block, fonts,
PDF layout knobs, tax_id, timezone)
- payment_term_templates (legacy) + payment_net_days_templates +
payment_timing_templates (124's split)
- quotes / quote_line_items / quote_line_item_presets / quote_action_tokens
- invoices / invoice_line_items / invoice_payment_log /
invoice_payment_check_tokens
- contracts / contract_blocks (13 system blocks seeded) /
contract_block_inclusions / contract_action_tokens
- event_payment_plans, customer_hour_entries, document_sequences
ALTER on upstream tables (hasColumn-guarded):
- events: quote_id, calendar columns (event_time_*, is_full_day),
event_reminder_*
- customer_accounts: billing_cadence/cycle_day, country_name,
feature_hours_logging, hourly_rate_minor
Seeds:
- RBAC perms (quotes/bills/contracts .view/.manage) + customers.create
split into edit + events (mig 134)
- Feature flags (quotes, bills, contracts, hoursLogging, taxReport,
calendar, calendarBooking, reminderEmails, crmDevelopment, messaging
— all default OFF)
- 30+ CRM app_settings rows (skonto/QR/reminder windows, payment
defaults, installment defaults, ToS, event reminder defaults)
- 4 + 5 + 4 payment-term system rows across the legacy + split tables
Email-template content moves out of the schema diff into three
runtime self-heal service files that idempotently create missing
rows + backfill empty translations on first access (per the maintainer's
"never ship compensation migrations" rule):
- backend/src/services/crmEmailTemplates.js (NEW) — quote_sent,
quote_accepted_*, quote_declined_admin, invoice_sent,
invoice_reminder_first/second, invoice_paid_receipt,
invoice_cancelled, invoice_payment_check,
invoice_paid_admin_notification, storno_issued
- backend/src/services/contractEmailTemplates.js — contract_sent,
contract_fully_signed, contract_signed_admin_notification
- backend/src/services/eventReminderTemplates.js — event_reminder_default
+ per-event-type variants
Smoke-tested on fresh sqlite DB: 84 migrations apply cleanly,
all CRM tables present, seeds populated.
Database Migrations
This directory contains database migrations for the PicPeak photo sharing platform.
Directory Structure
/core
Essential migrations that are always run for new deployments. These include:
init.js- Initial database schema creation- Backup service tables (029-035)
- Gallery feedback tables (033)
- Pre-generated watermarks (061)
/legacy
Migrations needed only when upgrading from older versions. New deployments can skip these as the core schema already includes all necessary tables and columns.
For New Deployments
If you're deploying this application for the first time:
- The
initializeDatabase()function insrc/database/db.jswill create all necessary tables - Only migrations in the
/coredirectory will be run - This ensures a clean, optimized database schema
For Existing Deployments
If you're upgrading from an older version:
- All migrations (both core and legacy) will be run in sequence
- The migration system tracks which migrations have been applied
- Only new migrations will be executed
Running Migrations
# Development
npm run migrate
# Production
npm run migrate:prod
Note on Duplicate Migration Numbers
The legacy directory contains renamed duplicates:
014_add_host_name_to_events_duplicate.js(was duplicate of 014)027_add_rate_limit_settings_duplicate.js(was duplicate of 027)
These have been renamed to avoid conflicts while preserving the migration history.