Documentation
¶
Overview ¶
Package dbseed applies version-control-owned dataset files to the framework-owned database pool.
It is the single place where Popcorn Web talks to github.com/shibukawa/dbtestify, so the CLI seed command and the test helpers share one dataset contract.
Index ¶
- Constants
- func Apply(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, ...) error
- func Assert(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, ...) (bool, string, error)
- func Resolve(directory string, names []string) ([]string, error)
- type Dialect
- type Executor
Constants ¶
const DefaultDir = "testdata/seed"
DefaultDir is the dataset directory relative to the project root for the CLI and to the test package directory for tests.
const Extension = ".yaml"
Extension is the only dataset file extension.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, paths []string) error
Apply loads each dataset through exec in the given order.
exec stays owned by the caller. Pass inTransaction when exec is already inside a transaction, in which case dbtestify neither commits nor rolls back and the caller's rollback undoes the seeding. Otherwise each dataset is applied in its own transaction. The first failure stops the run.
A dataset's own _operation block selects the per-table operation. dbtestify reads operations from the option struct rather than from the parsed dataset, so the caller has to carry them across — its CLI and HTTP API do the same. Omitting that step silently clear-inserts every table.
func Assert ¶
func Assert(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, paths []string) (bool, string, error)
Assert compares the database against each dataset and returns a plain-text diff for every mismatching table.
An exec already inside a transaction observes that transaction's uncommitted writes; a pool does not.
The boolean reports whether every dataset matched. A non-nil error means the comparison could not run at all.
Types ¶
type Dialect ¶
Dialect is the SQL flavor a dataset is applied with.
func ResolveDialect ¶
ResolveDialect derives the dialect from a driver://dsn configuration value.
type Executor ¶
Executor is the statement target datasets are applied through: dbtestify's driver-agnostic execution interface since its v0.5.0. A database/sql handle enters through FromSQL, the framework executor seam through FromRuntime.
func FromRuntime ¶
func FromRuntime(executor sqlbind.SQLExecutor) Executor
FromRuntime adapts a framework executor — the pool-level executor of a connection or the executor of an open transaction scope — to Executor. A native executor queries through its QueryRows; a database/sql handle goes through FromSQL. A nil executor returns nil, which Apply and Assert report as "no database to seed".