Loomio
Wed 13 Mar 2019 12:07PM

db:migrate fails on AddIndexToEventsOnPosAndParentId

J JosephK Public Seen by 35

Hi,
My instance was not updated since april 2017 (it’s bad :-/) and I get this error :
```
Migrating to AddIndexToEventsOnPosAndParentId (20170826033216)

== 20170826033216 AddIndexToEventsOnPosAndParentId: migrating =================

-- add_index(:events, [:parent_id, :position], {:order=>:position, :where=>"(parent_id IS NOT NULL)"})

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedObject: ERROR: operator class "position" does not exist for access method "btree"

: CREATE INDEX "index_events_on_parent_id_and_position" ON "events" ("parent_id" POSITION, "position" POSITION) WHERE (parent_id IS NOT NULL)

```
Is there a way to fix it ?

J

JosephK Wed 13 Mar 2019 5:27PM

I try to skip this migrate like this :

docker exec -ti loomio-db /bin/bash
su postgres
psql loomio_production
insert into schema_migrations (version) values ('20170826033216');

And run again

docker-compose run app rake db:migrate

4 others migrates fail for various reasons. I skipped them the same way and it seems to work.

But I don’t know if it’s dangerous for user’s data. I don't really understand the implications of these changes.
For now, I've only done this in a testing environment.
Do you think I can apply this in production without too much damage?

RG

Robert Guthrie Wed 13 Mar 2019 9:48PM

no. all migrations are required. skipping them will have bad consequences :)

RG

Robert Guthrie Wed 13 Mar 2019 9:51PM

@josephk - it looks like position is being interpreted as a keyword rather than a column name. I suggest you try editing the migration to be:

add_index(:events, [:parent_id, :position], {:order=>{position: :desc} , :where=>"(parent_id IS NOT NULL)"})

and see if that helps

J

JosephK Thu 14 Mar 2019 10:03AM

Ok, thank you.
It works for the first migrate error but I still get this error with the second one :
https://github.com/loomio/loomio/blob/master/db/migrate/20171221225240_migrate_versions_to_eventables_attempt_2.rb
```
Migrating to MigrateVersionsToEventablesAttempt2 (20171221225240)

== 20171221225240 MigrateVersionsToEventablesAttempt2: migrating ==============

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

undefined method token' for #<FormalGroup:0x000055db93b3e290>
Did you mean? to_key
``

And the third one (when the second is skipped) :
https://github.com/loomio/loomio/blob/master/db/migrate/20180305031829_add_notification_model.rb
```
Migrating to AddNotificationModel (20180305031829)

== 20180305031829 AddNotificationModel: migrating =============================

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

undefined method discussion' for nil:NilClass
``
On the other hand, it solved the problem on errors 4 and 5.

RG

Robert Guthrie Thu 14 Mar 2019 7:01PM

comment out initialized_with_token :token (line 10) in /app/models/group.rb for the migration (then uncomment it once you're through).

AddNotificationModel just updates precomputed strings.. it's technically optional.. so if it still fails you can skip that one, however I don't think you should be skipping any other migrations... that would give undefined behaviour..

good luck!

J

JosephK Fri 15 Mar 2019 10:25AM

It works! Thank you very much!

RG

Robert Guthrie Wed 20 Mar 2019 8:05PM

That's great! Pleased to hear it.

It would be good to talk more about how you can contribute back to our open source resources.

I'd be particularly keen to talk about french translation of our help.loomio.org resource if you have anyone who could help with that.