Skip to content

Terraform Provider

terraform {
required_providers {
pgmold = {
source = "fmguerreiro/pgmold"
version = "~> 0.3"
}
}
}
provider "pgmold" {}
resource "pgmold_schema" "app" {
schema_file = "${path.module}/schema.sql"
database_url = var.database_url
allow_destructive = false
}

Terraform diffs against the live database and applies only necessary migrations on changes.

NameTypeRequiredDescription
schema_filestringyesPath to SQL schema file
database_urlstringyesPostgreSQL connection URL
target_schemaslist(string)noPostgreSQL schemas to manage (default: ["public"])
allow_destructiveboolnoAllow DROP operations (default: false)
NameDescription
idResource identifier
schema_hashSHA256 hash of schema file
applied_atTimestamp of last migration
migration_countNumber of operations applied

Generate numbered migration files instead of applying directly:

resource "pgmold_migration" "app" {
schema_file = "${path.module}/schema.sql"
database_url = var.database_url
output_dir = "${path.module}/migrations"
prefix = "V" # Flyway-style prefix
}