ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
5.69k stars 254 forks source link

Error generating migrate diff - database snapshot #2564

Open duttmamta opened 6 months ago

duttmamta commented 6 months ago

Error:

We are getting the following error while generating migrate diff : Error: sql/migrate: taking database snapshot: postgres: unexpected column index 10

Context:

In our database schema.pg.hcl file, we have a named table configured with a partition over a boolean column (deleted). In one of our custom migrations, we created two partition tables (table_active & table_deleted). Could this be the cause of the problem? If so, Is it possible to add partition table support in your upcoming releases?

a8m commented 6 months ago

Hey @duttmamta đź‘‹

Can you please share an example that reproduce this issue? Also, what postgres version do you use?

duttmamta commented 6 months ago

We added the following table definition in schema.pg.hcl file:

table “Table1” {
   column “id” {
    null = false
    type = character_varying(40)
  }
   column “column1” {
    null = false
    type = character_varying(40)
  }
   column "deleted" {
    null    = false
    type    = boolean
    default = false
  }
  partition {
    type    = LIST
    columns = [column.deleted]
  }
}

There are several functions attached to the above table.

Atlas successfully created the following:

CREATE TABLE "public”.”Table1”
(
    "id"       character varying(40)  NOT NULL,
    “column1”       character varying(40)  NOT NULL,
    "deleted"         boolean                NOT NULL DEFAULT false
) PARTITION BY LIST ("deleted");

We created the following custom migration:

CREATE TABLE "public”.”Table1_active"
    PARTITION OF public.Table1
        FOR VALUES IN (false);

CREATE TABLE "public”.”
Table1_deleted”
    PARTITION OF public.Table1
        FOR VALUES IN (true);

When we drop column1 from the parent table , Atlas throws the following error upon creating the migration diff:

Error: sql/migrate: taking database snapshot: postgres: unexpected column index 10

We use Postgres version 14.4

duttmamta commented 6 months ago

Hi, Any updates on this please?

masseelch commented 6 months ago

@a8m