Skip to content
bitzorcas
EN

Guide

Database initialization

Schema management — SqlSugar CodeFirst initialization, CSV seed data loading, and schema update workflow.

Last updated

BitzOrcas uses SqlSugar CodeFirst for schema management instead of traditional EF Core migrations. Tables are created/updated from entity definitions, not from migration files.

Schema initialization modes

Terminal window
# Create/update schema + seed demo data
dotnet run --project src/Hosts/BitzOrcas.Api -- --init-schema --seed-demo
# Schema only (no seed data)
dotnet run --project src/Hosts/BitzOrcas.Api -- --init-schema
# Seed data only (schema must already exist)
dotnet run --project src/Hosts/BitzOrcas.Api -- --seed-only
# No schema init (default — enter web pipeline)
dotnet run --project src/Hosts/BitzOrcas.Api

What —init-schema does

  1. Reads PersistenceModelRegistry for all registered entities
  2. Calls SqlSugar CodeFirst to create/update tables
  3. Creates indexes defined in entity metadata
  4. Creates audit tables (7 sharded tables)
  5. Creates CAP Outbox tables
  6. Exits without entering the web pipeline

What —seed-demo does

  1. ISeedRunner discovers all ISeedStep implementations
  2. Executes steps in dependency order
  3. Each step reads CSV via CsvSeedReader
  4. Upserts via SqlSugar Storageable (safe to re-run)
  5. Produces a SeedRunReport with counts

Production considerations

  • Back up database before running --init-schema on existing data
  • Schema changes are additive-safe but may drop removed columns
  • Seed data is idempotent (Storageable upsert)

See also