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

Generates two migrations with the same timestamp #33

Open
leehericks opened this issue Sep 10, 2017 · 2 comments
Open

Generates two migrations with the same timestamp #33

leehericks opened this issue Sep 10, 2017 · 2 comments

Comments

@leehericks
Copy link

New example Rails 5.1.4 project, gems:

# Secure ALL the things!
gem 'devise'
gem 'neo4j', '~> 8.2.1'
gem 'devise-neo4j'

rails g neo4j:devise User generates:
20170910050708_create_user
20170910050708_devise_create_user_constraints_and_indexes

Running rails neo4j:migrate results in:

== 20170910050708 CreateUser: running... =======================================
 CYPHER CREATE CONSTRAINT ON (n:`User`) ASSERT n.`uuid` IS UNIQUE
== 20170910050708 CreateUser: migrated (0.0831s) ===============================

== 20170910050708 DeviseCreateUserConstraintsAndIndexes: running... ============
rails aborted!
Neo4j::Core::CypherSession::SchemaErrors::ConstraintValidationFailedError:   Cypher error:
  Neo.ClientError.Schema.ConstraintValidationFailed: Node(0) already exists with label `Neo4j::Migrations::SchemaMigration` and
property `migration_id` = '20170910050708'

/Users/leehericks/Developer/tests/neo4j_devise_test/bin/rails:9:in `require'
/Users/leehericks/Developer/tests/neo4j_devise_test/bin/rails:9:in `<top (required)>'
/Users/leehericks/Developer/tests/neo4j_devise_test/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Then I renamed to:
20170910050708_create_user
20170910050709_devise_create_user_constraints_and_indexes

Running rails neo4j:migrate results in:

== 20170910050708 CreateUser: running... =======================================
 CYPHER CREATE CONSTRAINT ON (n:`User`) ASSERT n.`uuid` IS UNIQUE
== 20170910050708 CreateUser: migrated (0.0661s) ===============================

== 20170910050709 DeviseCreateUserConstraintsAndIndexes: running... ============
rails aborted!
NotImplementedError: NotImplementedError
/Users/leehericks/Developer/tests/neo4j_devise_test/bin/rails:9:in `require'
/Users/leehericks/Developer/tests/neo4j_devise_test/bin/rails:9:in `<top (required)>'
/Users/leehericks/Developer/tests/neo4j_devise_test/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Not sure what's happening there...

@LXAfterDark
Copy link

LXAfterDark commented Jan 3, 2018

I ran into this exact same problem not moments ago. Did a little digging and here's what I found.

At first glance it appears that the DeviseCreateUserConstraintsAndIndexes migration is not being created correctly. I took a gamble and changed the migration created by devise-neo4j from this:

class DeviseCreateUserConstraintsAndIndexes < Neo4j::Migrations::Base
  def change
    add_index :User, :email, force: true
    add_index :User, :remember_token, force: true
    add_index :User, :reset_password_token, force: true
    # add_index :User, :confirmation_token, force: true
    # add_index :User, :unlock_token, force: true
    # add_index :User, :authentication_token, force: true
  end
end

to this:

class DeviseCreateUserConstraintsAndIndexes < Neo4j::Migrations::Base
  def up
    add_index :User, :email, force: true
    add_index :User, :remember_token, force: true
    add_index :User, :reset_password_token, force: true
    # add_index :User, :confirmation_token, force: true
    # add_index :User, :unlock_token, force: true
    # add_index :User, :authentication_token, force: true
  end

  def down
    # drop_index :User, :authentication_token, force: true
    # drop_index :User, :unlock_token, force: true
    # drop_index :User, :confirmation_token, force: true
    drop_index :User, :reset_password_token, force: true
    drop_index :User, :remember_token, force: true
    drop_index :User, :email, force: true
  end
end

and the migration completed successfully once I reset and re-ran it. Unfortunately since I'm relatively new to Rails (or Ruby for that matter), I can't tell you why this worked. My best guess (read: pure speculation) is that the NotImplementedError is indicative of Rails not expecting to see def change in the migration.

EDITED TO CLARIFY: I ran into the same problem with both migrations getting the same timestamp as well -- everything I outlined above was what I did to get the second migration to work after changing the timestamp on the second migration as outlined in @leehericks' post above. So, best as I can tell, there's two problems that need to be solved for... the overlapping timestamps and the content of the second migration file.

@cheerfulstoic
Copy link
Contributor

Hey @TheOneTrueLX thanks for this!

I think with your issue the problem is that the change method isn't supported by the neo4j gem's migrations. Probably it could be supported at some point.

I just created an issue in the neo4j gem repo to track this idea

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

3 participants