Skip to content

DB: store network as a typed enum/constraint and validate on write #252

Description

@Depo-dev

Summary

Constrain the network column to known values to prevent typos that silently split data.

Background & current behaviour

network is free TEXT with a default across soroban_events, api_keys, webhook_subscriptions, etc. A typo (tesnet) would create a separate, invisible data partition and cause auth/query mismatches.

Why this matters for MVP

Network is a primary scoping dimension (data isolation, auth). Uncontrolled values are a silent correctness hazard.

Proposed implementation

  1. Define the allowed set (pubnet, testnet, futurenet, local) — confirm the exact set used.
  2. Add a CHECK constraint (or an enum type) on network across the relevant tables via a migration + schema.sql.
  3. Normalise/validate network at write time in the indexer and API.
  4. Migration must handle any existing out-of-range values (map or reject with a documented step).

Acceptance criteria

  • Allowed network set defined + documented.
  • CHECK/enum constraint on network across relevant tables.
  • Writers validate/normalise network values.
  • Migration safely handles existing values.

Affected files / components

  • database/migrations/, database/schema.sql
  • crates/indexer/src/, services/api/

Testing & verification

Attempt to insert an invalid network and assert rejection; valid networks pass.

Related / dependencies

Touches auth (network in context) and event scoping.

Out of scope

Multi-network federation logic.


Target branch

All work for this issue MUST target the dev branch. Cut your feature branch from dev and open the pull request against dev, never against main. Any PR opened against main for this issue will be closed and asked to re-target dev.

Metadata

Metadata

Assignees

No one assigned

    Labels

    databasePostgres schema, migrations, queriesenhancementImprovement to existing behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions