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

[Question]Have compatibility for primary key option on foreign_key? #250

Closed
sizer opened this issue Jul 14, 2018 · 1 comment
Closed

[Question]Have compatibility for primary key option on foreign_key? #250

sizer opened this issue Jul 14, 2018 · 1 comment

Comments

@sizer
Copy link

sizer commented Jul 14, 2018

Hi, there. ridgepole is nice gem. Thank you for your publishing ;)

I encountered strange behavior.
Is this correct behaviour??

Schemafile

# -*- mode: ruby -*-
# vi: set ft=ruby :

create_table :users, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", id: false do |t|
  t.bigint :my_original_id, null: false
  t.index %i[my_original_id], unique: true
end

create_table :lessons, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
  t.bigint :user_id, null: false
  t.index %i[user_id],    name: :index_lessons_on_user_id
end
add_foreign_key :lessons, :users, primary_key: :my_original_id

https://github.com/mrdShinse/ridgepole/blob/0.7_test_foreign_key/Schemafile#L13

Result

shinse@edo:~/go/src/github.com/mrdShinse/ridgepole (0.7_test_foreign_key)
$ bundle exec ridgepole -c ./config.yml -a
Apply `Schemafile`
-- create_table("users", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :id=>false})
   -> 0.0098s
-- add_index("users", ["my_original_id"], {:unique=>true})
   -> 0.0233s
-- create_table("lessons", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8"})
   -> 0.0152s
-- add_index("lessons", ["user_id"], {:name=>"index_lessons_on_user_id"})
   -> 0.0288s
-- add_foreign_key("lessons", "users", {:primary_key=>:my_original_id})
   -> 0.0325s
shinse@edo:~/go/src/github.com/mrdShinse/ridgepole (0.7_test_foreign_key)
$ bundle exec ridgepole -c ./config.yml -a
Apply `Schemafile`
-- remove_foreign_key("lessons", "users")
   -> 0.0271s
-- add_foreign_key("lessons", "users", {:primary_key=>:my_original_id})
   -> 0.0257s

my opinion

Result should be Idempotent, I think.
But ridgepole always remove&create foreign_key.

I don't know well about how to implement this feature.
Can triage this issue??

@winebarrel
Copy link
Collaborator

Thank you for your report 😃
I fixed it.
Please try v0.7.4.

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