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
Patch for Issue 1259 -- New #1297
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9629da8
Added a template to create a migration when the model already exists.…
seanski 179cb2c
Changed the order of the devise_generator methods to create the model…
seanski 99d539b
Chagned the copy_devise_migration method to properly handle the :revo…
seanski 8ad414b
Added a helper to look for an modifying migration. If one is found d…
seanski File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
lib/generators/active_record/templates/migration_existing.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration | ||
def self.up | ||
change_table :<%= table_name %> do |t| | ||
t.database_authenticatable :null => false | ||
t.recoverable | ||
t.rememberable | ||
t.trackable | ||
|
||
# t.encryptable | ||
# t.confirmable | ||
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %> | ||
# t.token_authenticatable | ||
|
||
<% for attribute in attributes -%> | ||
t.<%= attribute.type %> :<%= attribute.name %> | ||
<% end -%> | ||
#Uncomment below if timestamps were not included in your original model. | ||
t.timestamps | ||
end | ||
add_index :<%= table_name %>, :email, :unique => true | ||
add_index :<%= table_name %>, :reset_password_token, :unique => true | ||
# add_index :<%= table_name %>, :confirmation_token, :unique => true | ||
# add_index :<%= table_name %>, :unlock_token, :unique => true | ||
# add_index :<%= table_name %>, :authentication_token, :unique => true | ||
end | ||
|
||
def self.down | ||
#By default, we don't want to make any assumption about how to roll back a migration when your | ||
#model already existed. Please edit below which fields you would like to remove in this migration. | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my attempt at this, I had added "rm_" versions of each of the... well not sure what the word is, but the
t.recoverable
,t.trackable
etc.. that way the down could be just the inverse of the things up top. So if you hadt.recoverable
in the up, you could putt.rm_recoverable
in the down. Easy enough to mirror after editing.Not sure what to do with the attribute section though, as I'm not sure what those are for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That wouldn't be a bad thing to do; however, I'm worried what would happen if we had a user model with email, for example. It would be deleted when we the migration is rolled back, and this would not be ideal. I still think it's better for the user to write the rollback code. Maybe we could add the rollback code in the migration but leave it commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - the existing email thing is very tricky. It's in
database_authenticatable
aleady and will blow up as it stands currently if the existing model has that field (as many will, I suspect).I had thought to possibly handle that by detecting the existence of the model, and somehow checking its fields? Then instead of
database_authenticatable
, something else, likedatabase_authenticatable_existing_email
, and the complementary rm would follow suit? Getting very complicated, though...