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

ActiveRecord: AUTO_INCREMENT on composite key can not dump #30894

Closed
dominion525 opened this issue Oct 15, 2017 · 1 comment
Closed

ActiveRecord: AUTO_INCREMENT on composite key can not dump #30894

dominion525 opened this issue Oct 15, 2017 · 1 comment
Assignees

Comments

@dominion525
Copy link

I use partition table on MySQL. Partition table have composite key.
This column set AUTO_INCREMENT.
but it not wrote auto_increment: true on db/schema.rb.

Steps to reproduce

class CreateArticles < ActiveRecord::Migration[5.1]
  def up
    create_table :articles, id: false do |t|
      t.integer  :id,        null: false
      t.datetime :posted_at, null: false
      t.text     :content,   null: false
    end

    execute 'ALTER TABLE articles ADD PRIMARY KEY(id, posted_at);'
    execute 'ALTER TABLE articles MODIFY id BIGINT(20) NOT NULL AUTO_INCREMENT;'
  end
end
mysql> DESC articles;
+-----------+------------+------+-----+---------+----------------+
| Field     | Type       | Null | Key | Default | Extra          |
+-----------+------------+------+-----+---------+----------------+
| id        | bigint(20) | NO   | PRI | NULL    | auto_increment |
| posted_at | datetime   | NO   | PRI | NULL    |                |
| content   | text       | NO   |     | NULL    |                |
+-----------+------------+------+-----+---------+----------------+

Expected behavior

  create_table "articles", primary_key: ["id", "posted_at"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
    t.bigint "id", null: false, auto_increment: true
    t.datetime "posted_at", null: false
    t.text "content", null: false
  end

Actual behavior

missing auto_increment: true ...

  create_table "articles", primary_key: ["id", "posted_at"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
    t.bigint "id", null: false
    t.datetime "posted_at", null: false
    t.text "content", null: false
  end

System configuration

Rails version: 5.1.4

Ruby version: 2.4.2

MySQL version: 2.4.2

mysql2 gem version: 0.4.9

@kamipo kamipo self-assigned this Oct 15, 2017
@kamipo kamipo closed this as completed in 9493d45 Oct 15, 2017
kamipo added a commit that referenced this issue Oct 15, 2017
Currently `AUTO_INCREMENT` is implicitly used in the default primary key
definition. But `AUTO_INCREMENT` is not only used for single column
primary key, but also for composite primary key. In that case,
`auto_increment: true` should be dumped explicitly in the
`db/schema.rb`.

Fixes #30894.
@kamipo
Copy link
Member

kamipo commented Oct 15, 2017

Thanks for reporting the issue. I've fixed it and backported in 8b6e694.

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

No branches or pull requests

2 participants