Skip to main content

@idpass/data-collect-core / initializeDatacollectDatabase

Function: initializeDatacollectDatabase()

initializeDatacollectDatabase(postgresUrl): Promise<void>

Defined in: db/initialize.ts:48

Orchestrates datacollect database initialization by delegating to each service/adapter's own initialize() method. This ensures DDL is defined in exactly one place (the owning service) and run in dependency order.

All statements use IF NOT EXISTS so this function is idempotent and safe to call on every startup.

Initialization order (respects FK dependencies):

  1. entities + potential_duplicates (PostgresEntityStorageAdapter)
  2. events + audit_log + sync_metadata (PostgresEventStorageAdapter)
  3. attachments + attachment_data (PostgresAttachmentStorageAdapter)
  4. areas (AreaService)
  5. user_assignments + entity_overrides (AssignmentService, depends on areas)
  6. entity_snapshots (SnapshotService)

Parameters

postgresUrl

string

Returns

Promise<void>