/*
  Warnings:

  - You are about to drop the column `account_id` on the `transaction` table. All the data in the column will be lost.
  - Added the required column `connected_accounts` to the `transaction` table without a default value. This is not possible if the table is not empty.

*/
-- First, add the new column with default empty JSON
ALTER TABLE "transaction" ADD COLUMN "connected_accounts" JSONB DEFAULT '{}';

-- Migrate EVM accounts
UPDATE "transaction"
SET "connected_accounts" = jsonb_build_object('evmAddress', account_id)
WHERE "chain_type" = 'evm';

-- Migrate NEAR accounts
UPDATE "transaction"
SET "connected_accounts" = jsonb_build_object('nearAddress', account_id)
WHERE "chain_type" = 'near';

-- Migrate SUI accounts
UPDATE "transaction"
SET "connected_accounts" = jsonb_build_object('suiAddress', account_id)
WHERE "chain_type" = 'sui';

-- Drop the old column after migration
ALTER TABLE "transaction" DROP COLUMN "account_id";

-- Make the new column NOT NULL now that data is migrated
ALTER TABLE "transaction" ALTER COLUMN "connected_accounts" SET NOT NULL;

-- Remove the default constraint
ALTER TABLE "transaction" ALTER COLUMN "connected_accounts" DROP DEFAULT;
