Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Add migration_version variable to migration generator for rails 5 compatibility #2470

Merged
merged 2 commits into from
Jan 30, 2018

Conversation

jackellenberger
Copy link
Contributor

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 the migration_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.

@@ -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'

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

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
)

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

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.

@stinnett-casey
Copy link

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"
Copy link

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked perfectly.

@Skowt
Copy link

Skowt commented Jan 20, 2018

Any reason this still hasn't been merged 🤔

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

Successfully merging this pull request may close these issues.

8 participants