Skip to content

pgflow-dev/atlas-alter-type-schema-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Atlas Bug: Missing Schema Qualification in ALTER TYPE Statements

Atlas generates ALTER TYPE statements without schema qualification, causing migrations to fail.

Expected:

ALTER TYPE "myschema"."my_type" ADD ATTRIBUTE "field_b" text;

Actual:

ALTER TYPE "my_type" ADD ATTRIBUTE "field_b" text;

PostgreSQL cannot find the type without schema qualification when it's not in the search_path.

Prerequisites

Reproduction Steps

Quick Start

make  # Cleans, reproduces bug, and verifies it

The bug is in migrations/*_add_field.sql - check it yourself!

Manual Steps

Initial migration (already committed in migrations/*_initial.sql):

-- Generated by Atlas - correct schema qualification
CREATE SCHEMA "myschema";
CREATE TYPE "myschema"."my_type" AS ("field_a" text);  -- ✓ Only field_a

Current schema (schemas/schema.sql - already has field_b added):

create schema myschema;
create type myschema.my_type as (
  field_a text,
  field_b text  -- Added (this triggers the bug)
);

1. Generate migration to see the bug

atlas migrate diff --config file://atlas/atlas.hcl --env local add_field
# or: make reproduce

This creates migrations/*_add_field.sql:

ALTER TYPE "my_type" ADD ATTRIBUTE "field_b" text;  -- ✗ Missing schema!

Bug confirmed: Should be ALTER TYPE "myschema"."my_type"

Check the file yourself:

cat migrations/*_add_field.sql

2. Reset to try again

make clean

Technical Details

Why it fails:

  • PostgreSQL cannot find type without schema when it's not in search_path
  • Inconsistent: Atlas correctly qualifies CREATE TYPE but not ALTER TYPE
  • Can modify wrong type if same name exists in multiple schemas

Environment:

  • Atlas: v0.37.1-8ee9008-canary (tested 2025-10-06)
  • PostgreSQL: 15 (via built-in Docker image)

Workaround: Manually add schema qualification to generated migrations


Project: https://github.com/pgflow-dev/pgflow

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published