-- AlterColumn: Change source_order_id from BIGINT to VARCHAR(50)
-- This is needed because planting-service sends orderNo as string (e.g., PLT1765391584505Q0Q6QD)

-- Step 1: Drop the existing index
DROP INDEX IF EXISTS "idx_source_order";

-- Step 2: Rename the old column
ALTER TABLE "reward_ledger_entries" RENAME COLUMN "source_order_id" TO "source_order_no";

-- Step 3: Change the column type from BIGINT to VARCHAR(50)
ALTER TABLE "reward_ledger_entries"
    ALTER COLUMN "source_order_no" TYPE VARCHAR(50) USING "source_order_no"::VARCHAR(50);

-- Step 4: Recreate the index on the new column
CREATE INDEX "idx_source_order" ON "reward_ledger_entries"("source_order_no");
