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

generated migration has type error : type integer mismatch type bigint #115

Closed
Ex-Ark opened this issue May 25, 2020 · 1 comment · Fixed by #117
Closed

generated migration has type error : type integer mismatch type bigint #115

Ex-Ark opened this issue May 25, 2020 · 1 comment · Fixed by #117
Labels

Comments

@Ex-Ark
Copy link

Ex-Ark commented May 25, 2020

The migration currently generated by the gem itself looks like this :
lib/generators/doorkeeper/openid_connect/templates/migration.rb.erb

class CreateDoorkeeperOpenidConnectTables < ActiveRecord::Migration<%= migration_version %>
  def change
    create_table :oauth_openid_requests do |t|
      t.integer :access_grant_id, null: false
      t.string :nonce, null: false
    end

    add_foreign_key(
      :oauth_openid_requests,
      :oauth_access_grants,
      column: :access_grant_id,
      on_delete: :cascade
    )
  end
end

When running migration I have the following error :

== 20191104103725 CreateDoorkeeperOpenidConnectTables: migrating ==============
      01 -- create_table(:oauth_openid_requests)
      01    -> 0.0031s
      01 -- add_foreign_key(:oauth_openid_requests, :oauth_access_grants, {:column=>:access_grant_id})
      01 rake aborted!
      01 StandardError: An error has occurred, all later migrations canceled:
      01
      01 Column `access_grant_id` on table `oauth_openid_requests` does not match column `id` on `oauth_access_grants`, which has type `bigint(20)`. To resolve this issue, change the type of the `access_grant_id` column…

      01 Original message: Mysql2::Error: Can't create table `OIDC_welcom_provider_production`.`oauth_openid_requests` (errno: 150 "Foreign key constraint is incorrectly formed")

It appears the default type for id on other tables is bigint, thus the foreign key must match the same type
Rails indeed started using bigint as default a while ago : PR rails/rails#26266

I successfully fixed it locally by editing the generated migration to

class CreateDoorkeeperOpenidConnectTables < ActiveRecord::Migration[6.0]
  def change
    create_table :oauth_openid_requests do |t|
      t.bigint :access_grant_id, null: false
      t.string :nonce, null: false
    end

    add_foreign_key(
      :oauth_openid_requests,
      :oauth_access_grants,
      column: :access_grant_id
    )
  end
end

Anyone ever had the same problem ?

nbulaj added a commit that referenced this issue May 30, 2020
Fix migration template to use `references` migrations DSL to properly create column type.
Also add an index for reference

Fixes #115
nbulaj added a commit that referenced this issue May 30, 2020
Fix migration template to use `references` migrations DSL to properly create column type.
Also add an index for reference

Fixes #115
@nbulaj
Copy link
Member

nbulaj commented May 30, 2020

Thanks @Ex-Ark , fixed in #117 🙇

@nbulaj nbulaj added the bug label May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants