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 CreateSeedTable(ctx context.Context, conn *pgx.Conn) error
- func DropUserSchemas(ctx context.Context, conn *pgx.Conn) error
- func DumpData(ctx context.Context, config pgconn.Config, w io.Writer, exec ExecFunc, ...) error
- func DumpRole(ctx context.Context, config pgconn.Config, w io.Writer, exec ExecFunc, ...) error
- func DumpSchema(ctx context.Context, config pgconn.Config, w io.Writer, exec ExecFunc, ...) 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 []SeedFile, conn *pgx.Conn, fsys fs.FS) error
- func SeedGlobals(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs.FS) error
- type DumpOptionFunc
- type ExecFunc
- type MigrationFile
- type SeedFile
Constants ¶
View Source
const ( SET_LOCK_TIMEOUT = "SET 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 version, coalesce(name, '') as name, statements FROM supabase_migrations.schema_migrations" LIST_MIGRATION_VERSION = "SELECT version FROM supabase_migrations.schema_migrations ORDER BY version" CREATE_SEED_TABLE = "CREATE TABLE IF NOT EXISTS supabase_migrations.seed_files (path text NOT NULL PRIMARY KEY, hash text NOT NULL)" UPSERT_SEED_FILE = "INSERT INTO supabase_migrations.seed_files(path, hash) VALUES($1, $2) ON CONFLICT (path) DO UPDATE SET hash = EXCLUDED.hash" SELECT_SEED_TABLE = "SELECT path, hash FROM supabase_migrations.seed_files" )
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", "pgmq", "pgsodium", "pgtle", `supabase\_migrations`, "vault", } )
View Source
var (
InternalSchemas = []string{
"information_schema",
"pg_*",
"_analytics",
"_realtime",
"_supavisor",
"auth",
"extensions",
"pgbouncer",
"realtime",
"storage",
"supabase_functions",
"supabase_migrations",
"cron",
"dbdev",
"graphql",
"graphql_public",
"net",
"pgmq",
"pgsodium",
"pgsodium_masks",
"pgtle",
"repack",
"tiger",
"tiger_data",
"timescaledb_*",
"_timescaledb_*",
"topology",
"vault",
}
)
Functions ¶
func ApplyMigrations ¶
func CreateMigrationTable ¶
TODO: support overriding `supabase_migrations.schema_migrations` with user defined <schema>.<table>
func CreateSeedTable ¶
func DropUserSchemas ¶
func DumpSchema ¶ added in v1.0.2
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 ¶
Types ¶
type DumpOptionFunc ¶ added in v1.0.2
type DumpOptionFunc func(*pgDumpOption)
func WithColumnInsert ¶ added in v1.0.2
func WithColumnInsert(use bool) DumpOptionFunc
func WithComments ¶ added in v1.0.2
func WithComments(keep bool) DumpOptionFunc
func WithSchema ¶ added in v1.0.2
func WithSchema(schema ...string) DumpOptionFunc
func WithoutTable ¶ added in v1.0.2
func WithoutTable(table ...string) DumpOptionFunc
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)
type SeedFile ¶
func GetPendingSeeds ¶
Click to show internal directories.
Click to hide internal directories.