migrations

package
v1.63.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package migrations holds the versioned migrations of the index, one directory per dialect, and applies them on open. After a schema change, regenerate the ent client and run `go run ./gen -name <change>` from index/sql/migrations to append a migration to every dialect's directory.

Index

Constants

View Source
const (
	SQLite   = "sqlite"
	Postgres = "postgres"
)

Dialects the index migrates.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, db *sql.DB, dialect string) error

Apply brings db to the newest migration of the dialect, recording what it applied in the atlas_schema_revisions table. A database that is up to date is left alone. Concurrent callers take turns: an SQLite migration is one write transaction, a Postgres one holds an advisory lock.

func ApplyDir

func ApplyDir(ctx context.Context, db *sql.DB, dialect string, dir migrate.Dir, table, lock string) error

ApplyDir is Apply for a schema that ships its own migrations: dir is applied on top of whatever else the database holds, its history kept in the table named table and its Postgres runs serialised under lock.

func Diff

func Diff(ctx context.Context, db *sql.DB, dialect string, dir migrate.Dir, name string) error

Diff writes into dir the migration named name that takes the schema dir reproduces to the current ent schema, replaying dir on db, an empty scratch database of the dialect that is left empty again. It returns migrate.ErrNoPlan when dir is up to date.

func DiffWith

func DiffWith(ctx context.Context, differ Differ, dir migrate.Dir, name string) error

DiffWith is Diff for a schema that ships its own migrations.

func Dir

func Dir(dialect string) (*migrate.MemDir, error)

Dir returns a dialect's migration directory, checksum file included.

func EntDialect

func EntDialect(d string) string

EntDialect is the ent dialect of a migration dialect.

func ReadDir

func ReadDir(fsys fs.FS, dialect string) (*migrate.MemDir, error)

ReadDir loads the migration directory named dialect from fsys, checksum file included, for a schema that ships its own migrations.

Types

type Differ

type Differ interface {
	NamedDiff(ctx context.Context, name string, opts ...entschema.MigrateOption) error
}

Differ is what a generated ent migrate package's NewSchema returns.

func Schema

func Schema(db *sql.DB, dialect string) Differ

Schema is goback's index schema over db in the dialect.

Directories

Path Synopsis
Command gen appends a migration to every dialect's directory when the ent schema changed.
Command gen appends a migration to every dialect's directory when the ent schema changed.
Package generate writes the migration an ent schema change needs, for goback's own index and for anything built on goback that keeps its own schema the same way.
Package generate writes the migration an ent schema change needs, for goback's own index and for anything built on goback that keeps its own schema the same way.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL