devise-activegraph icon indicating copy to clipboard operation
devise-activegraph copied to clipboard

Generates two migrations with the same timestamp

Open leehericks opened this issue 8 years ago • 2 comments

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

leehericks avatar Sep 10 '17 05:09 leehericks

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.

LXAfterDark avatar Jan 03 '18 15:01 LXAfterDark

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

cheerfulstoic avatar Jan 06 '18 14:01 cheerfulstoic