xataio / pgroll

PostgreSQL zero-downtime migrations made easy

Home Page:https://www.xata.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

References to tables from the same migration don't work

ilyakooo0 opened this issue · comments

commented
{
  "name": "1_initial_schema",
  "operations": [
    {
      "create_table": {
        "columns": [
          {
            "name": "id",
            "nullable": false,
            "pk": true,
            "type": "uuid",
            "unique": true
          }
        ],
        "name": "lang"
      }
    },
    {
      "create_table": {
        "columns": [
          {
            "name": "id",
            "nullable": false,
            "pk": true,
            "type": "uuid",
            "unique": true
          },
          {
            "name": "lang",
            "nullable": false,
            "pk": true,
            "references": {
              "column": "id",
              "name": "translation_lang_lang_id",
              "on_delete": "RESTRICT",
              "table": "lang"
            },
            "type": "uuid",
            "unique": false
          }
        ],
        "name": "translation"
      }
    }
  ]
}

When I try to reference a table added within the same migration I get the following error:

Error: migration is invalid: column reference to column "lang" in table "translation" is invalid: table "lang" does not exist

This is really misleading and results from the way temporary tables are created during a migration.

I think pgroll should ccount for the temporary table names and create the references using temporary table names.

commented

This issue also means that it is not always possible to encode all desired changes in a single migration.

Hi @ilyakooo0 👋 , thanks for opening the issue.

The inability to reference objects created in earlier operations in the same migration is tracked in #239 as part of the v1 milestone.

It is a significant limitation and one that will need to be removed before a v1.