migrate

package
v0.1.15 Latest Latest
Warning

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

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

README

HCL migrations

migrate.Apply reconciles PostgreSQL tables with Atlas HCL and runs colocated SQL migrations. Every bundle should use a stable WithName when more than one bundle can share a database.

SQL files default to the post-Atlas phase. Directives are read from the leading comment header:

-- phase: pre
-- dependsOn: 001_extensions.sql
-- runs: always
-- transaction: false
  • phase is pre or post; omitted means post.
  • dependsOn uses paths relative to the migration root. Dependencies are topologically ordered and changes rerun all transitive dependents.
  • scripts are transactional by default; the SQL and its SHA-256 migration log commit atomically.

Atlas-style PostgreSQL role and permission blocks may live in the same HCL files as tables. The OSS migration layer supports roles and memberships plus schema, table, column, and sequence permissions. Managed grants are reconciled exactly within the bundle's metadata scope; unrelated roles and grants are left untouched. Different scopes must not manage the same role or grantee/object pair.

Documentation

Overview

Package migrate applies declarative Atlas HCL schemas to PostgreSQL databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, connection string, schemaFS fs.FS, opts ...Option) error

Apply loads colocated HCL and SQL migrations from schemaFS. SQL scripts marked phase pre run before the Atlas realm diff; all other SQL defaults to the post phase. Declared PostgreSQL roles and permissions are reconciled last. Tables absent from a partial schema bundle are never dropped unless WithTableDrops is supplied.

Types

type Option

type Option func(*options)

Option configures an HCL migration.

func WithDir

func WithDir(dir string) Option

WithDir selects the root containing colocated HCL and SQL migrations.

func WithExclude

func WithExclude(patterns ...string) Option

WithExclude excludes database objects from Atlas inspection. Values use Atlas's schema inspection patterns (for example "table.column").

func WithName

func WithName(name string) Option

WithName sets the metadata scope used for SQL hashes and managed security. It should be stable and unique for each migration bundle sharing a database.

func WithTableDrops

func WithTableDrops() Option

WithTableDrops allows HCL files to remove tables. Drops are suppressed by default so a partial schema bundle cannot delete tables owned by consumers.

func WithVariables

func WithVariables(input map[string]cty.Value) Option

WithVariables supplies values for HCL variable blocks and security expressions.

Jump to

Keyboard shortcuts

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