migration

package
v1.190.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SET_LOCK_TIMEOUT         = "SET LOCAL lock_timeout = '4s'"
	CREATE_VERSION_SCHEMA    = "CREATE SCHEMA IF NOT EXISTS supabase_migrations"
	CREATE_VERSION_TABLE     = "CREATE TABLE IF NOT EXISTS supabase_migrations.schema_migrations (version text NOT NULL PRIMARY KEY)"
	ADD_STATEMENTS_COLUMN    = "ALTER TABLE supabase_migrations.schema_migrations ADD COLUMN IF NOT EXISTS statements text[]"
	ADD_NAME_COLUMN          = "ALTER TABLE supabase_migrations.schema_migrations ADD COLUMN IF NOT EXISTS name text"
	INSERT_MIGRATION_VERSION = "INSERT INTO supabase_migrations.schema_migrations(version, name, statements) VALUES($1, $2, $3)"
	DELETE_MIGRATION_VERSION = "DELETE FROM supabase_migrations.schema_migrations WHERE version = ANY($1)"
	DELETE_MIGRATION_BEFORE  = "DELETE FROM supabase_migrations.schema_migrations WHERE version <= $1"
	TRUNCATE_VERSION_TABLE   = "TRUNCATE supabase_migrations.schema_migrations"
	SELECT_VERSION_TABLE     = "SELECT * FROM supabase_migrations.schema_migrations"
	LIST_MIGRATION_VERSION   = "SELECT version FROM supabase_migrations.schema_migrations ORDER BY version"
)

Variables

View Source
var (
	ErrMissingRemote = errors.New("Found local migration files to be inserted before the last migration on remote database.")
	ErrMissingLocal  = errors.New("Remote migration versions not found in local migrations directory.")
)
View Source
var (
	//go:embed queries/drop.sql
	DropObjects string
	//go:embed queries/list.sql
	ListSchemas string

	// Initialised by postgres image and owned by postgres role
	ManagedSchemas = []string{
		`information\_schema`,
		`pg\_%`,
		`\_analytics`,
		`\_realtime`,
		`\_supavisor`,
		"pgbouncer",
		"pgsodium",
		"pgtle",
		`supabase\_migrations`,
		"vault",
	}
)

Functions

func ApplyMigrations

func ApplyMigrations(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error

func CreateMigrationTable

func CreateMigrationTable(ctx context.Context, conn *pgx.Conn) error

TODO: support overriding `supabase_migrations.schema_migrations` with user defined <schema>.<table>

func DropUserSchemas added in v1.186.0

func DropUserSchemas(ctx context.Context, conn *pgx.Conn) error

func FindPendingMigrations

func FindPendingMigrations(localMigrations, remoteMigrations []string) ([]string, error)

Find unapplied local migrations older than the latest migration on remote, and remote migrations that are missing from local.

func ListLocalMigrations

func ListLocalMigrations(migrationsDir string, fsys fs.FS, filter ...func(string) bool) ([]string, error)

func ListRemoteMigrations

func ListRemoteMigrations(ctx context.Context, conn *pgx.Conn) ([]string, error)

func ListUserSchemas added in v1.186.0

func ListUserSchemas(ctx context.Context, conn *pgx.Conn, exclude ...string) ([]string, error)

func SeedData

func SeedData(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error

func SeedGlobals

func SeedGlobals(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error

Types

type MigrationFile

type MigrationFile struct {
	Version    string
	Name       string
	Statements []string
}

func NewMigrationFromFile

func NewMigrationFromFile(path string, fsys fs.FS) (*MigrationFile, error)

func NewMigrationFromReader

func NewMigrationFromReader(sql io.Reader) (*MigrationFile, error)

func ReadMigrationTable

func ReadMigrationTable(ctx context.Context, conn *pgx.Conn) ([]MigrationFile, error)

func (*MigrationFile) ExecBatch

func (m *MigrationFile) ExecBatch(ctx context.Context, conn *pgx.Conn) error

func (*MigrationFile) ExecBatchWithCache

func (m *MigrationFile) ExecBatchWithCache(ctx context.Context, conn *pgx.Conn) error

Jump to

Keyboard shortcuts

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