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.