Skip to content

inheriting indexes can get a > 64 character limit error #3

@ghost

Description

Issue:
When mti adds indexes to children tables it can fail if the generated index name is too long. Rails' add_index function generates the index name by default using the table name and the column your indexing (or array of columns if it's a compound index). If this constructed table name is > 64 characters then add_index will fail.

One thing to note is the :name attribute isn't being passed to add_index when constructing the child index in "active_record-mti/lib/active_record/mti/connection_adapters/postgresql/schema_statements.rb #create_table"

Steps to Reproduce:
Add the following to the spec/schema.rb file and try to run tests.

create_table :vehicles, force: true do |t|
    t.string :color
    t.string :type # Inheritance column
    t.timestamps null: false
  end

  add_index :vehicles, [:color, :type]

  create_table "vehicles/trucks", force: true, inherits: :vehicles do |t|
    t.integer :bed_size
  end

  # different schema of parent
  create_table "vehicles/some_really_really_really_really_long_table_name", force: true, inherits: :vehicles do |t|
    t.integer :long_size
  end

  # same schema of parent
  create_table "vehicles/some_other_really_really_really_long_table_name", force: true, inherits: :vehicles do |t|
end

Expected Result:
It creates the compound indexes on the children tables.

Actual Result:
The following error is thrown:
Index name 'index_vehicles/some_really_really_really_really_long_table_name_on_color_and_type' on table 'vehicles/some_really_really_really_really_long_table_name' is too long; the limit is 63 characters (ArgumentError)

Metadata

Metadata

Assignees

No one assigned

    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