-- Migration: Add missing columns to sales_receipts table
-- Date: 2025-10-02
-- Description: Add type, transactiontype, data, and timestamp columns to support frontend sync operations

-- Add type column (for distinguishing between 'taxcore', 'Normal', etc.)
ALTER TABLE sales_receipts ADD COLUMN IF NOT EXISTS type text DEFAULT NULL;

-- Add transactiontype column (for 'Sale', 'Refund', etc.)
ALTER TABLE sales_receipts ADD COLUMN IF NOT EXISTS transactiontype text DEFAULT NULL;

-- Add data column (for storing arbitrary JSON data from frontend)
ALTER TABLE sales_receipts ADD COLUMN IF NOT EXISTS data jsonb DEFAULT NULL;

-- Add timestamp column (for frontend sync tracking)
ALTER TABLE sales_receipts ADD COLUMN IF NOT EXISTS timestamp bigint DEFAULT NULL;

-- Verify columns were added
SELECT column_name, data_type, is_nullable, column_default 
FROM information_schema.columns 
WHERE table_name = 'sales_receipts' 
AND column_name IN ('type', 'transactiontype', 'data', 'timestamp')
ORDER BY column_name;
