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

Allow index creation upon table creation #203

Open
saintazunya opened this issue Nov 12, 2023 · 1 comment
Open

Allow index creation upon table creation #203

saintazunya opened this issue Nov 12, 2023 · 1 comment

Comments

@saintazunya
Copy link

Hi community,

I recently found that we are not able to create index upon table creation.
Here is a minimum reproduce of errors:

{
  "name": "01_test",
  "operations": [
    {
      "create_table": {
        "name": "test_user",
        "columns": [
          {
            "name": "user_id",
            "type": "int",
            "pk": true
          }
        ]
      }
    },
    {
      "create_index": {
        "name": "idx_test_user_id",
        "table": "test_user",
        "columns": [
          "user_id"
        ]
      }
    }
  ]
}

I got an error saying Failed to start migration: migration is invalid: table "test_user" does not exist when running migrations.
We can walkaround by spliting migrations into two files, but it comes with a problem that might break the zero-downtime promise.

  • We need to run migration sequencely, that said, I have to complete 01_create_tableand then run02_create_index`.
  • At which time point 01_create_table is completed and I will not have a chance to roll it back if there is a bug in DDL.

If index creation is allowed upon table creation, it will make the migrations more compact.

Thanks!

@andrew-farries
Copy link
Collaborator

Hi, thanks for reporting this issue @saintazunya.

This is a limitation with the current implementation of migrations that contain multiple operations; later operations in the migration typically can't reference resources created by earlier operations in the same migration.

This is a significant restriction and one we hope to remove in an upcoming release.

For this specific case of adding an index to a table it would also make sense to be able to do it as part of the create table operation, in the same way that constraints and foreign keys can be added at table creation time.

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