Skip to content

Allow index creation upon table creation #203

@saintazunya

Description

@saintazunya

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!

Metadata

Metadata

Assignees

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