✨ feat(user): foundation for parallel-safe BDD isolation (T12 stage 1/2) #34
Reference in New Issue
Block a user
Delete Branch "feat/bdd-parallel-isolation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
First half of T12 (parallel-safe BDD scenario isolation, ADR-0025 follow-up).
PR #28 had to revert
BDD_SCHEMA_ISOLATIONbecause the existingSetupScenarioSchemacreated empty per-scenario schemas — no migrations were run on them. This PR adds the missing factory that opens a*PostgresRepositoryfrom an arbitrary DSN AND runs AutoMigrate on that connection.What's new
NewPostgresRepositoryFromDSN(cfg, dsn) (*PostgresRepository, error)Opens a Postgres repo via an explicit DSN, runs AutoMigrate. The DSN can include
search_path=<schema>so the migrations create tables in a per-scenario schema instead of public.BuildSchemaIsolatedDSN(cfg, schemaName) stringBuilds a DSN with
search_path=<schema>from a base config object.Existing
Close()reusedFor per-scenario teardown.
Verification
New integration test
TestNewPostgresRepositoryFromDSN_SchemaIsolationverifies:userstable inside the per-scenario schemaCreateUserthrough the isolated repo writes ONLY into the per-scenario schemapublic.userssees ZERO rows for the test user (proves no leak)Skips gracefully when
DLC_DATABASE_HOSTis not set (CI safe).Out of scope (T12 stage 2/2)
pkg/bdd/testserver/SetupScenarioSchema*server.Serverper scenario (requires aNewServerWithUserRepofactory)-p 1fromscripts/run-bdd-tests.shafter parallel safety is achievedThat follow-up PR will be smaller because this one establishes the contract.
Architectural note (per code-reviewer SOLID/DDD checklist)
Test plan
go build ./pkg/user/...PASSgo test ./pkg/...PASS (all packages, no regression)