ALTER TABLE users ALTER COLUMN role SET DEFAULT 'merchant';
UPDATE users SET role = 'merchant' WHERE role = 'distributor';
DROP INDEX IF EXISTS idx_users_invite_code;
DROP INDEX IF EXISTS idx_users_parent_id;
ALTER TABLE users DROP COLUMN IF EXISTS invite_code;
ALTER TABLE users DROP COLUMN IF EXISTS parent_id;

ALTER TABLE merchants ADD COLUMN IF NOT EXISTS features TEXT NOT NULL DEFAULT 'products,orders,wallet,api,callbacks';
ALTER TABLE merchants ADD COLUMN IF NOT EXISTS fee_rate_bp BIGINT NOT NULL DEFAULT 0;
ALTER TABLE merchants ADD COLUMN IF NOT EXISTS fee_fixed_amount BIGINT NOT NULL DEFAULT 0;

ALTER TABLE skins DROP COLUMN IF EXISTS commission;

DROP INDEX IF EXISTS idx_orders_distributor_id;
ALTER TABLE orders DROP COLUMN IF EXISTS distributor_id;
ALTER TABLE orders DROP COLUMN IF EXISTS commission_amt;

ALTER TABLE fulfillment_orders ADD COLUMN IF NOT EXISTS base_amount BIGINT NOT NULL DEFAULT 0;
ALTER TABLE fulfillment_orders ADD COLUMN IF NOT EXISTS fee_rate_bp BIGINT NOT NULL DEFAULT 0;
ALTER TABLE fulfillment_orders ADD COLUMN IF NOT EXISTS fee_fixed_amount BIGINT NOT NULL DEFAULT 0;
ALTER TABLE fulfillment_orders ADD COLUMN IF NOT EXISTS service_fee_amount BIGINT NOT NULL DEFAULT 0;
UPDATE fulfillment_orders SET base_amount = amount WHERE base_amount = 0;
