Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References to tables from the same migration don't work #347

Open
ilyakooo0 opened this issue Apr 25, 2024 · 2 comments
Open

References to tables from the same migration don't work #347

ilyakooo0 opened this issue Apr 25, 2024 · 2 comments

Comments

@ilyakooo0
Copy link

{
  "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.

@ilyakooo0
Copy link
Author

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

@andrew-farries
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants