Skip to content

atlas schema inspect returns incorrect partition key after dropping column from PostgreSQL partitioned table #3615

@h6ah4i

Description

@h6ah4i

When running atlas schema inspect against a PostgreSQL database where a column has been dropped from a partitioned table, atlas returns an incorrect partition range definition.

Steps to reproduce:

PostgreSQL setup

CREATE TABLE "partitioned_table" (
    "user_id" char(36) NOT NULL,
    "attr_1" text NOT NULL,
    "attr_2" text NOT NULL,
    "attr_3" text NOT NULL,
    "created_at" timestamp with time zone NOT NULL,
    "updated_at" timestamp with time zone NOT NULL,
    PRIMARY KEY ("user_id", "attr_1", "created_at")
)
PARTITION BY RANGE ("created_at");

--- `atlas schema inspect` timing #1

ALTER TABLE "partitioned_table" DROP COLUMN "attr_3";

--- `atlas schema inspect` timing #2

atlas schema inspect result (timing #1)

table "partitioned_table" {
  schema = schema.public
  column "user_id" {
    null = false
    type = character(36)
  }
  column "attr_1" {
    null = false
    type = text
  }
  column "attr_2" {
    null = false
    type = text
  }
  column "attr_3" {
    null = false
    type = text
  }
  column "created_at" {
    null = false
    type = timestamptz
  }
  column "updated_at" {
    null = false
    type = timestamptz
  }
  primary_key {
    columns = [column.user_id, column.attr_1, column.created_at]
  }
  partition {
    type    = RANGE
    columns = [column.created_at]
  }
}
schema "public" {
  comment = "standard public schema"
}

atlas schema inspect result (timing #2)

👉 The partition definition incorrectly uses the updated_at column instead of created_at.

table "partitioned_table" {
  schema = schema.public
  column "user_id" {
    null = false
    type = character(36)
  }
  column "attr_1" {
    null = false
    type = text
  }
  column "attr_2" {
    null = false
    type = text
  }
  column "created_at" {
    null = false
    type = timestamptz
  }
  column "updated_at" {
    null = false
    type = timestamptz
  }
  primary_key {
    columns = [column.user_id, column.attr_1, column.created_at]
  }
  partition {
    type    = RANGE
    columns = [column.updated_at]
  }
}
schema "public" {
  comment = "standard public schema"
}

Expected behavior:

Even after dropping attr_3, atlas schema inspect should continue to report the partition definition as PARTITION BY RANGE ("created_at"), but it instead switches to updated_at.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions