-- 024_crtc_trade_name.sql
-- Add trade name support to canada_crtc_orders.

BEGIN;

-- Add trade name columns
ALTER TABLE canada_crtc_orders
  ADD COLUMN IF NOT EXISTS trade_name TEXT,
  ADD COLUMN IF NOT EXISTS add_trade_name BOOLEAN DEFAULT FALSE;

-- Expand company_type CHECK to include numbered_tradename
-- Drop old constraint and recreate (PG doesn't support ALTER CONSTRAINT)
ALTER TABLE canada_crtc_orders DROP CONSTRAINT IF EXISTS canada_crtc_orders_company_type_check;
ALTER TABLE canada_crtc_orders ADD CONSTRAINT canada_crtc_orders_company_type_check
  CHECK (company_type IN ('numbered', 'numbered_tradename', 'named'));

COMMIT;
