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

fix migration file for rails 5 #985

Closed
wants to merge 15 commits into from
Closed

fix migration file for rails 5 #985

wants to merge 15 commits into from

Conversation

jonhue
Copy link

@jonhue jonhue commented Aug 24, 2017

The migration file generated with rails generate doorkeeper:migration did not have the appropriate [5.x] when I was installing it.

Rails version: 5.1.3

So here is a fix.

migration_version: migration_version
)
@migration_version = Rails::VERSION::STRING[0..2].to_f
migration_template 'migration.rb.erb', 'db/migrate/create_doorkeeper_tables.rb'

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.
Line is too long. [83/80]

'add_owner_to_application_migration.rb',
'db/migrate/add_owner_to_application.rb'
'add_owner_to_application_migration.rb.erb',
'db/migrate/add_owner_to_application.rb',

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.

@@ -7,8 +7,9 @@ class Doorkeeper::ApplicationOwnerGenerator < Rails::Generators::Base

def application_owner
migration_template(
'add_owner_to_application_migration.rb',
'db/migrate/add_owner_to_application.rb'
'add_owner_to_application_migration.rb.erb',

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.

@@ -1,4 +1,4 @@
class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration
class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration<%= migration_version %>

Choose a reason for hiding this comment

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

unterminated string meets end of file

'add_previous_refresh_token_to_access_tokens.rb',
'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
'add_previous_refresh_token_to_access_tokens.rb.erb',
'db/migrate/add_previous_refresh_token_to_access_tokens.rb',

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.

@@ -12,8 +12,9 @@ def self.next_migration_number(path)
def previous_refresh_token
if no_previous_refresh_token_column?
migration_template(
'add_previous_refresh_token_to_access_tokens.rb',
'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
'add_previous_refresh_token_to_access_tokens.rb.erb',

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.

)
end

def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Choose a reason for hiding this comment

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

Trailing whitespace detected.

@@ -8,12 +8,19 @@ class Doorkeeper::PreviousRefreshTokenGenerator < Rails::Generators::Base
def self.next_migration_number(path)
ActiveRecord::Generators::Base.next_migration_number(path)
end

Choose a reason for hiding this comment

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

Trailing whitespace detected.

@nbulaj
Copy link
Member

nbulaj commented Aug 27, 2017

@jonhue take a look at the #981 - already in master.

@jonhue
Copy link
Author

jonhue commented Aug 27, 2017

@nbulaj

It has not been done for the other migration like adding applications & stuff.

@jcamejo
Copy link

jcamejo commented Sep 6, 2017

Hi
i'm having some troubles with this fix, the migration is being generated without the rails version, even with the master fix. If i download the gem into my local environment it creates the migration with the version but not with the remote one. Is there anything that i'm doing wrong?

i've updated the gem to the last version.

Thanks!

@jonhue
Copy link
Author

jonhue commented Sep 6, 2017

@jcamejo

This branch works fine. Master does not.
For now, I suggest you just add it manually.

@nbulaj
Copy link
Member

nbulaj commented Oct 17, 2017

Hi @maclover7 . I think we can merge it with the master branch.

@jonhue one thing that I would change: Rails version check. Why not to compare integers, not strings? I mean why not Rails::VERSION::MAJOR >= 5 instead of Rails.version >= "5.0.0" ? It works, yes, but looks a little bit hacky

@jonhue
Copy link
Author

jonhue commented Oct 17, 2017

@nbulaj Here you go ...

I want to point out though, that the other generators in this repository are sing a string comparison:
https://github.com/doorkeeper-gem/doorkeeper/blob/master/lib/generators/doorkeeper/migration_generator.rb#L21

@nbulaj
Copy link
Member

nbulaj commented Oct 17, 2017

@jonhue take a look at the TravisCI log - there are some errors :)

@jonhue
Copy link
Author

jonhue commented Oct 17, 2017

@nbulaj Seems like poor little Travis didn't like that change too much :)

@nbulaj
Copy link
Member

nbulaj commented Jan 26, 2018

Hi @jonhue . Some comments:

1. Could you please check Rails version as:

if Rails::VERSION::MAJOR >= 5

As I said before, I don't like the way of string comparison. Let's check integers :)

2. Could you add some specs for this feature (check Rails version in the specs, and if it more than 5, then check if migration template has a version specification) ? You can take a look at some already existing examples

After that please rebase your commits and squash them into one, and add an entry to NEWS.md. Thanks for your work and patience!

@nbulaj nbulaj self-assigned this Jan 27, 2018
@nbulaj nbulaj closed this in 200b72f Jan 31, 2018
nbulaj added a commit that referenced this pull request Jan 31, 2018
Add migration versioning for migration templates if ActiveRecord greater
than 5.0. Add specs to ensure valid generator implementation.
@nbulaj
Copy link
Member

nbulaj commented Jan 31, 2018

Thanks @jonhue for your work! I already fixed this issue with some corrections and specs to prepare a new release of the gem.

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

Successfully merging this pull request may close these issues.

4 participants