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

SequelizeDatabaseError: column "deleteToken" does not exist #895

Closed
mathiasblc opened this Issue Jul 9, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@mathiasblc

mathiasblc commented Jul 9, 2018

Hello,

Since I updated CodiMD it began to compain about not setting the secretSession key in config.json. I putted here a 64 characters length random key and now I get the folowing error:

Jul  9 17:19:31 hackmd node[13135]: 2018-07-09T17:19:31.375Z - error:  message=column "deleteToken" does not exist, name=SequelizeDatabaseError, stack=SequelizeDatabaseError: column "deleteToken" does not exist
Jul  9 17:19:31 hackmd node[13135]:     at Query.formatError (/opt/codimd/node_modules/sequelize/lib/dialects/postgres/query.js:357:14)
Jul  9 17:19:31 hackmd node[13135]:     at Result.<anonymous> (/opt/codimd/node_modules/sequelize/lib/dialects/postgres/query.js:88:19)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]:     at Result.emit (events.js:211:7)
Jul  9 17:19:31 hackmd node[13135]:     at Result.Query.handleError (/opt/codimd/node_modules/pg/lib/query.js:163:8)
Jul  9 17:19:31 hackmd node[13135]:     at Client.<anonymous> (/opt/codimd/node_modules/pg/lib/client.js:188:26)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]:     at Connection.emit (events.js:211:7)
Jul  9 17:19:31 hackmd node[13135]:     at Socket.<anonymous> (/opt/codimd/node_modules/pg/lib/connection.js:133:12)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]: SequelizeDatabaseError: column "deleteToken" does not exist
Jul  9 17:19:31 hackmd node[13135]:     at Query.formatError (/opt/codimd/node_modules/sequelize/lib/dialects/postgres/query.js:357:14)
Jul  9 17:19:31 hackmd node[13135]:     at Result.<anonymous> (/opt/codimd/node_modules/sequelize/lib/dialects/postgres/query.js:88:19)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]:     at Result.emit (events.js:211:7)
Jul  9 17:19:31 hackmd node[13135]:     at Result.Query.handleError (/opt/codimd/node_modules/pg/lib/query.js:163:8)
Jul  9 17:19:31 hackmd node[13135]:     at Client.<anonymous> (/opt/codimd/node_modules/pg/lib/client.js:188:26)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]:     at Connection.emit (events.js:211:7)
Jul  9 17:19:31 hackmd node[13135]:     at Socket.<anonymous> (/opt/codimd/node_modules/pg/lib/connection.js:133:12)
Jul  9 17:19:31 hackmd node[13135]:     at emitOne (events.js:116:13)
Jul  9 17:19:31 hackmd node[13135]: 2018-07-09T17:19:31.417Z - info: ::ffff:10.10.10.10 - - [09/Jul/2018:17:19:31 +0000] "POST /login HTTP/1.1" 500 148 "https://pad.unixcorn.org/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"

Thanks in advance for your help.

🙏

@Kemyke

This comment has been minimized.

Kemyke commented Jul 13, 2018

I experienced the same thing when i restore a database from v0.5.1.
Maybe a migration script is missing?

Can someone help us doing this migration from the old HackMD?

@mathiasblc

This comment has been minimized.

mathiasblc commented Jul 21, 2018

Does somebody can help please? Any clue? :-/

@SISheogorath

This comment has been minimized.

Member

SISheogorath commented Jul 21, 2018

@SISheogorath SISheogorath added the bug label Jul 27, 2018

@SISheogorath SISheogorath added this to the 1.2.1 Release milestone Jul 27, 2018

@mathiasblc

This comment has been minimized.

mathiasblc commented Jul 27, 2018

Hello @SISheogorath, thanks for answering.

I took care of running all the steps mentioned in the READMEs upgrade section. Sadly errors aren't related to the #894 PR.

I'll provide some logs soon.

@Kemyke

This comment has been minimized.

Kemyke commented Aug 13, 2018

Ok, now i can make things work. Here is what i think and what is did.
The problem is with the migration process itself.
When the new version creates the SequelizeMeta table it is empty. So the sequelizer tries to run all the migrations from the migration folder. Some of them are fail because the columns they try to create already exist.
So when i removed the following migrations, the others succeded and the hackmd is up and running:

  • 20150702001020-update-to-0_3_1.js
  • 20160112220142-note-add-lastchange.js
  • 20160420180355-note-add-alias.js
  • 20160515114000-user-add-tokens.js
  • 20160703062241-support-authorship.js
  • 20161009040430-support-delete-note.js
  • 20161201050312-support-email-signin.js

Without these scripts the migration can be completed. It is interesting that 20180306150303-fix-enum also fails but it does not stop the migration process. Maybe that should be the correct behaviour in case of the other scripts too.

However migration deletion is not the best solution because in the future sequelizer will try to run this scripts again and the migration process will break again. So i will manually insert these lines into the SequelizeMeta as they were successfully migrated.

This is far from ideal but this is the only way i can achieve the update.
@SISheogorath Am i right, that the SequelizeMeta table should be populated with all the old migration lines and the migration process should be 0.x -> 0.5.2 -> 1.x In this case there won't be a problem like this.

@mathiasblc hope this helps

@SISheogorath

This comment has been minimized.

Member

SISheogorath commented Sep 24, 2018

Migrations should work now. The recent changes resolved all problems on the demo instance and also on some user setups so I hope this is fixed.

In some minor cases you may need to add a new default to the SequelizeMeta table for createdAt and updatedAt. Doing this is up to everyone who faces it manually since we don't directly control this table and I really try to avoid adding migrations for that as well.

Hope this helps everyone. I also purposed a change that, when you use npm start, will run the db migrations on every startup. We already do this in the container image.

@mcnesium

This comment has been minimized.

Contributor

mcnesium commented Sep 28, 2018

I just updated my instance that runs on Docker to v1.2.0 doing git pull, docker-compose down and docker-compose up -d and the migration did not work, obviously. The log had

error: SequelizeDatabaseError: column owner.deleteToken does not exist

as mentioned earlier in this issue.

Since I came here via search engine, I would like to drop a note how I fixed it: I added the missing column manually :)

Disclaimer: this is pretty hacky, use at your own risk!

Enter the database container and run psql using the hackmd user:

$ docker exec -ti hackmd_db_1 psql -U hackmd

Being inside this, check whether the column exists:

hackmd=# \d+ "Users"

If missing, add the column:

hackmd=# ALTER TABLE public."Users" ADD COLUMN "deleteToken" uuid;

Check again, the missing column deleteToken should be there now.

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