Documentation
¶
Index ¶
- type Baseline
- type DB
- func (db *DB) Close() error
- func (db *DB) CreateExtensions(extensions []string) error
- func (db *DB) CreateTables(models []interface{}) error
- func (db *DB) RegisterModels(models []interface{}) error
- func (db *DB) ResetTables(models []interface{}) error
- func (db *DB) RollbackLastMigration(migrations *migrate.Migrations) error
- func (db *DB) RunMigrations(migrations *migrate.Migrations) error
- func (db *DB) RunMigrationsFromBaseline(baseline Baseline, migrations *migrate.Migrations) error
- type DBModel
- type Option
- type PaginableModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Baseline ¶ added in v1.27.0
type Baseline struct {
// SQL is the output of pg_dump --schema-only of a database that has run
// every migration up to and including Floor. Empty when the app has no baseline yet.
SQL string
// Floor is the highest name among the deleted migration files, as bun stores
// it in the name column (the digits before the first underscore, not the
// file name); SQL holds it and everything below it. Every migration named
// at or below it must have its file deleted.
Floor string
}
Baseline - A schema snapshot that stands in for every migration up to its floor.
type DB ¶
type DB struct {
*bun.DB
// MigrationDB is a second pool for migrations and the schema baseline load,
// with no statement or read timeout and its own lock timeout. It is nil
// when the driver does not provide one, then migrations run on DB.
MigrationDB *bun.DB
}
func (*DB) Close ¶ added in v1.27.0
Close - Closes the migration pool, when there is one, and then the main pool
func (*DB) CreateExtensions ¶
CreateExtensions - Creates a database extension if it doesn't already exist. Extensions are a Postgres concept, so requesting any on another dialect is an error rather than a silent no-op.
func (*DB) CreateTables ¶
CreateTables - Creates the database schema if it doesn't already exist
func (*DB) RegisterModels ¶
RegisterModels - Registers many-to-many relationship
func (*DB) ResetTables ¶
ResetTables - Drops and recreates the database schema
func (*DB) RollbackLastMigration ¶
func (db *DB) RollbackLastMigration(migrations *migrate.Migrations) error
RollbackLastMigration - Rolls back the last applied group of migrations. Each migration is unmarked only after its Down succeeds, so a failed Down stays applied. It returns nil when the set is empty or no registered migration is applied.
func (*DB) RunMigrations ¶
func (db *DB) RunMigrations(migrations *migrate.Migrations) error
RunMigrations - Executes all pending migrations. Each one is marked as applied only after its Up succeeds, so a failed migration stays pending and the next start retries it: every migration must be safe to run twice. Rolling back is an explicit call to RollbackLastMigration.
func (*DB) RunMigrationsFromBaseline ¶ added in v1.27.0
func (db *DB) RunMigrationsFromBaseline(baseline Baseline, migrations *migrate.Migrations) error
RunMigrationsFromBaseline - Loads the baseline into a fresh database, or checks an existing one is not behind it, then runs the pending migrations.
type DBModel ¶
type DBModel interface {
// Validate checks the model for logical and business-rule correctness.
Validate() error
// Insert validates and inserts the model into the DB.
Insert(ctx context.Context, db bun.IDB) error
// Update validates and updates the model in the DB.
Update(ctx context.Context, db bun.IDB) error
// Delete removes the model from the DB.
Delete(ctx context.Context, db bun.IDB) error
}
DBModel defines the minimal interface for a model that can be persisted.
type Option ¶
func WithExtensions ¶
func WithRegistrableModels ¶
func WithRegistrableModels(models []interface{}) Option
type PaginableModel ¶
type PaginableModel interface {
// GetCursor returns a stable, opaque value representing the record’s
// position in the sorted result set.
GetCursor() string
// GetSortField returns the DB column used for ordering in pagination queries.
GetSortField() string
// GetSortValue returns the value of the sort field for this record.
GetSortValue() interface{}
// GetUniqueField returns the DB column that uniquely identifies this record.
GetUniqueField() string
// GetUniqueValue returns the value of the unique field for this record.
GetUniqueValue() interface{}
}
PaginableModel defines the minimal interface for cursor-based pagination.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
jsonfmt
Package jsonfmt holds the JSON formatter the compose dialects use in place of bun v1.3.0's, which mis-escapes the text \u0000 (https://github.com/uptrace/bun/issues/1472).
|
Package jsonfmt holds the JSON formatter the compose dialects use in place of bun v1.3.0's, which mis-escapes the text \u0000 (https://github.com/uptrace/bun/issues/1472). |
|
pgtest
Package pgtest is test support for apps that test against a real PostgreSQL: it creates a uniquely named database per test run, empties it between tests, drops it at the end, and sweeps the databases left behind by runs that died.
|
Package pgtest is test support for apps that test against a real PostgreSQL: it creates a uniquely named database per test run, empties it between tests, drops it at the end, and sweeps the databases left behind by runs that died. |