-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add migration_version variable to migration generator for rails 5 compatibility #2470
Conversation
@@ -27,4 +27,10 @@ def migration_file_name | |||
def migration_class_name | |||
migration_name.camelize | |||
end | |||
|
|||
def migration_version | |||
if Rails.version.start_with? '5' |
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.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -13,7 +13,7 @@ def self.source_root | |||
end | |||
|
|||
def generate_migration | |||
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}" | |||
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}", migration_version: migration_version |
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.
Line is too long. [126/80]
migration_template("paperclip_migration.rb.erb", | ||
"db/migrate/#{migration_file_name}", | ||
migration_version: migration_version | ||
) |
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.
Closing method call brace must be on the same line as the last argument when opening brace is on the same line as the first argument.
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}" | ||
migration_template("paperclip_migration.rb.erb", | ||
"db/migrate/#{migration_file_name}", | ||
migration_version: migration_version |
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.
Put a comma after the last parameter of a multiline method call.
This looks like a great solution. What is stopping this from being merged? |
@@ -27,4 +29,10 @@ def migration_file_name | |||
def migration_class_name | |||
migration_name.camelize | |||
end | |||
|
|||
def migration_version | |||
if Rails.version.start_with? "5" |
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.
[SUG] Let's do it compatible with higher versions:
if Rails.version.to_i >= 5
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.
This worked perfectly.
Any reason this still hasn't been merged 🤔 |
Problem
Relevant Issue : Rails 5 does not allow classes to inherit directly from ActiveRecord::Migration without specifying a version. This prevents basic actions such as
db:migrate
.Solution
If the rails version is >= 5.x, pass a
migration_version
variable to themigration_template
function to ensure that[5.x]
is appended to the migration function declaration.For similar code from a more trusted source, see Devise's implementation.
Concerns
Hey there's no test for this change! But there are no tests for any of the paperclip generator functions. It's late maybe I'll write em later.