{{/* Base DDL template with common structure */}} {{- define "ddl_header" -}} -- DDL Operation: {{.Operation}} -- Schema: {{.Schema}} -- Object: {{.ObjectName}} {{- end -}} {{- define "ddl_footer" -}} -- End of {{.Operation}} {{- end -}} {{/* Base ALTER TABLE structure */}} {{- define "alter_table_base" -}} ALTER TABLE {{.SchemaName}}.{{.TableName}} {{block "alter_operation" .}}{{end}}; {{- end -}} {{/* Common existence check pattern */}} {{- define "exists_check" -}} DO $$ BEGIN IF NOT EXISTS ( {{block "exists_query" .}}{{end}} ) THEN {{block "create_statement" .}}{{end}} END IF; END; $$; {{- end -}} {{/* Common drop pattern */}} {{- define "drop_if_exists" -}} {{block "drop_type" .}}{{end}} IF EXISTS {{.SchemaName}}.{{.ObjectName}}; {{- end -}}