Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyMigrations(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error
- func CreateMigrationTable(ctx context.Context, conn *pgx.Conn) error
- func DropUserSchemas(ctx context.Context, conn *pgx.Conn) error
- func FindPendingMigrations(localMigrations, remoteMigrations []string) ([]string, error)
- func ListLocalMigrations(migrationsDir string, fsys fs.FS, filter ...func(string) bool) ([]string, error)
- func ListRemoteMigrations(ctx context.Context, conn *pgx.Conn) ([]string, error)
- func ListUserSchemas(ctx context.Context, conn *pgx.Conn, exclude ...string) ([]string, error)
- func SeedData(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error
- func SeedGlobals(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error
- type MigrationFile
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 CreateMigrationTable ¶
TODO: support overriding `supabase_migrations.schema_migrations` with user defined <schema>.<table>
func DropUserSchemas ¶ added in v1.186.0
func FindPendingMigrations ¶
Find unapplied local migrations older than the latest migration on remote, and remote migrations that are missing from local.
func ListLocalMigrations ¶
func ListRemoteMigrations ¶
func ListUserSchemas ¶ added in v1.186.0
Types ¶
type MigrationFile ¶
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
Click to show internal directories.
Click to hide internal directories.