-- Rollback tracecoin security hardening.

DROP TRIGGER IF EXISTS trg_tracecoin_ledger_no_delete ON tracecoin_ledger;
DROP TRIGGER IF EXISTS trg_tracecoin_ledger_no_update ON tracecoin_ledger;
DROP FUNCTION IF EXISTS tracecoin_ledger_immutable();
DROP FUNCTION IF EXISTS lock_tracecoin_wallet(UUID);

DROP INDEX IF EXISTS idx_tracecoin_ledger_type;
DROP INDEX IF EXISTS idx_tracecoin_ledger_wallet_created;
DROP INDEX IF EXISTS uq_tracecoin_ledger_wallet_reference_type;

ALTER TABLE tracecoin_ledger DROP CONSTRAINT IF EXISTS tracecoin_ledger_type_valid;
ALTER TABLE tracecoin_ledger DROP CONSTRAINT IF EXISTS tracecoin_ledger_amount_nonzero;
ALTER TABLE tracecoin_ledger DROP CONSTRAINT IF EXISTS tracecoin_wallets_balance_consistent;
ALTER TABLE tracecoin_wallets DROP CONSTRAINT IF EXISTS tracecoin_wallets_reserved_nonneg;
ALTER TABLE tracecoin_wallets DROP CONSTRAINT IF EXISTS tracecoin_wallets_balance_nonneg;

ALTER TABLE tracecoin_ledger DROP COLUMN IF EXISTS metadata;
ALTER TABLE tracecoin_ledger DROP COLUMN IF EXISTS actor_user_id;
ALTER TABLE tracecoin_ledger DROP COLUMN IF EXISTS balance_after;
