dbschema 0.1.1

Define database schema's as HCL files, and generate idempotent SQL migrations
Documentation
variable "cols" {
  default = {
    id   = { type = "serial", nullable = false }
    name = { type = "text",   nullable = true }
  }
}

table "users" {
  dynamic "column" {
    for_each = var.cols
    labels   = [each.key]
    content {
      type     = each.value.type
      nullable = each.value.nullable
    }
  }
}

test "dynamic_columns" {
  assert = [
    "SELECT COUNT(*) = 2 FROM information_schema.columns WHERE table_schema='public' AND table_name='users'"
  ]
  assert_fail = [
    "INSERT INTO public.users(id) VALUES (NULL)"
  ]
}