Documentation
¶
Overview ¶
Package postgres is the PostgreSQL Dialect for github.com/gflydev/db/migrate.
Every migration file runs inside its own transaction (SupportsTransactionalDDL reports true): PostgreSQL allows DDL inside a transaction, so a failing statement leaves no partial effect.
Index ¶
- type Dialect
- func (Dialect) CreateMigrationsTableSQL(table string) string
- func (Dialect) Lock(ctx context.Context, conn *sql.Conn, key string) error
- func (Dialect) Name() string
- func (Dialect) Open() (*sql.DB, error)
- func (Dialect) Placeholder(argPos int) string
- func (Dialect) SupportsTransactionalDDL() bool
- func (Dialect) Unlock(ctx context.Context, conn *sql.Conn, key string) error
- func (Dialect) UpsertMigrationSQL(table string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct{}
Dialect implements migrate.Dialect for PostgreSQL. It is stateless; the zero value (Dialect{}) is ready to use.
func (Dialect) CreateMigrationsTableSQL ¶
CreateMigrationsTableSQL returns the CREATE TABLE IF NOT EXISTS statement for table, matching the schema documented in the migrate package's README (migration, batch, status, run_count, checksum, migrated_at, rolled_back_at).
func (Dialect) Lock ¶
Lock acquires a session-scoped PostgreSQL advisory lock keyed by the hash of key, blocking until it is available. The lock is released by Unlock on the same conn — advisory locks are tied to the session (connection) that took them, not to a transaction.
func (Dialect) Open ¶
Open reads the same DB_HOST/DB_PORT/DB_NAME/DB_USERNAME/DB_PASSWORD/DB_SSL_MODE environment variables as github.com/gflydev/db/psql and returns a pgx-backed connection pool. It does not verify connectivity — callers that need to fail fast on a bad connection should call (*sql.DB).PingContext themselves.
func (Dialect) Placeholder ¶
Placeholder returns PostgreSQL's numbered placeholder ("$1", "$2", ...) for argument position argPos.
func (Dialect) SupportsTransactionalDDL ¶
SupportsTransactionalDDL always returns true: PostgreSQL rolls back DDL inside a failed transaction like any other statement.
func (Dialect) UpsertMigrationSQL ¶
UpsertMigrationSQL returns an INSERT ... ON CONFLICT DO UPDATE statement for table, taking (migration, batch, run_count, checksum) as $1-$4 and always setting status to migrate.StatusUp and migrated_at to the current time.