migrate

package
v1.0.0-beta.231 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

README

View SQL Helper

Generate SQL definitions for ent.View schemas:

make generate-view-sql

This writes tools/migrate/views.sql by loading openmeter/ent/schema via Ent's schema loader and emitting Postgres CREATE VIEW statements from EntSQL view annotations.

Documentation

Overview

A very lightweigh migration tool to replace `ent.Schema.Create` calls.

Index

Constants

View Source
const IgnoreMarker = "-- migration:ignore"
View Source
const (
	MigrationsTable = "schema_om"
)

Variables

View Source
var ErrNoChange = migrate.ErrNoChange
View Source
var OMMigrationsConfig = MigrationsConfig{
	FS:             omMigrations,
	FSPath:         "migrations",
	StateTableName: MigrationsTable,
}

Functions

func AdoptLegacyEnt

func AdoptLegacyEnt(ctx context.Context, db *sql.DB, connectionString string, logger *slog.Logger) error

AdoptLegacyEnt brings an unversioned database created by Ent to the frozen migration baseline. It intentionally stops at the baseline so the normal migration command remains responsible for upgrading from that version to the target OpenMeter version.

func NewLogger

func NewLogger(log *slog.Logger) migrate.Logger

Types

type FS

type FS interface {
	fs.ReadDirFS
	fs.ReadFileFS
}

type Migrate

type Migrate struct {
	// contains filtered or unexported fields
}

func New

func New(options MigrateOptions) (*Migrate, error)

New creates a new migrate instance.

func (*Migrate) CloseOrLogError

func (m *Migrate) CloseOrLogError()

func (*Migrate) Down

func (m *Migrate) Down() error

func (*Migrate) Force

func (m *Migrate) Force(version uint) error

Force records version as the current clean migration version without applying migrations. It is intended for adopting databases brought to a verified baseline outside the migration history.

func (*Migrate) LatestVersion

func (m *Migrate) LatestVersion() (uint, error)

func (*Migrate) Migrate

func (m *Migrate) Migrate(version uint) error

func (*Migrate) Up

func (m *Migrate) Up() error

func (*Migrate) WaitForMigrationJob

func (m *Migrate) WaitForMigrationJob(waitOpts ...WaitForMigrationOption) error

type MigrateOptions

type MigrateOptions struct {
	ConnectionString string
	Migrations       MigrationsConfig
	Logger           *slog.Logger
}

func (*MigrateOptions) Validate

func (m *MigrateOptions) Validate() error

type MigrationsConfig

type MigrationsConfig struct {
	FS             fs.FS
	FSPath         string
	StateTableName string
}

func (*MigrationsConfig) Validate

func (m *MigrationsConfig) Validate() error

type SourceWrapper

type SourceWrapper struct {
	// contains filtered or unexported fields
}

func NewSourceWrapper

func NewSourceWrapper(fsys fs.FS) *SourceWrapper

func (*SourceWrapper) Open

func (s *SourceWrapper) Open(name string) (fs.File, error)

func (*SourceWrapper) ReadDir

func (s *SourceWrapper) ReadDir(path string) ([]fs.DirEntry, error)

func (*SourceWrapper) ReadFile

func (s *SourceWrapper) ReadFile(name string) ([]byte, error)

type WaitForMigrationOption

type WaitForMigrationOption func(*waitForMigrationOptions)

Directories

Path Synopsis
cmd
viewgen command

Jump to

Keyboard shortcuts

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