Factories
Factories live under models/factories and build model entities for tests and seeds. Andurel-owned declarations stay synchronized with the model Entity; custom helpers belong outside generated blocks.
Generate and sync
Model generation creates a matching factory unless you pass --skip-factory. Refresh factories after Entity changes:
1andurel sync factory Product --check
2andurel sync factory Product --sync
3andurel sync factories --check --json
4andurel sync factories --sync
sync factory refreshes one factory. sync factories covers every managed factory declaration and requires --check or --sync. Prefer --check in CI.
Build and create
Generated factories expose in-memory builders and persistence helpers:
1product := factories.BuildProduct(
2 factories.WithProductName("Orbit"),
3 factories.WithProductPriceCents(1200),
4)
5
6created, err := factories.CreateProduct(ctx, db,
7 factories.WithProductName("Orbit"),
8 factories.WithProductActive(true),
9)
10if err != nil {
11 return err
12}
13
14batch, err := factories.CreateProducts(ctx, db, 5,
15 factories.WithProductActive(true),
16)
BuildProduct leaves auto-managed fields (ID, timestamps) at zero. CreateProduct persists through the model API and returns the entity with database-assigned values. Option functions (WithProductName, …) override defaults from go-faker / sensible stubs.
Seeds
Named seed compositions in root seeds/ should call factories and exported model APIs, then run through andurel db seed. See Migrations & Seeding and Testing.