Upgrade failed - is my deployment broken now? Can I fix it?
I fear I may have broken my twenty deployment. Here is what I did:
I thought I was on v0.55.1 so I just did
1. dbdump
2. podman-compose down
3. Edit .env file setting TAG=0.55 (was TAG=latest before)
4. podman-compose up
Now, twenty got up immediately but it did not download new images. So I did the following:
* podman-compose down
* podman-compose pull
Now it downloaded new images.
I started twenty:
* podman-compose up -d
Now twenty starts up. But I cannot login. When I enter a username, I get this error: QueryFailedError
I then tried inspecting the database dump. And now it seems that I may have been on 0.51.0 and not 0.55.1 as I thought....
So have I completely broken my deployment? OR can I fix this? If so, how?
130 Replies
Hello @EbenezerIbiza I would recommend recovering from a
0.51
and proceed to an incremental upgrade up to 0.55
THanks for your reply. So do I just change TAG=0.51 in the .env and then do podman-compose pull again and bring back up?
And then restore the database and proceed with incremental upgrade?
@prastoin so I tried doing this:
* stopped twenty
* changed TAG in .env to 0.51
* did podman-compose pull
* Then broought up twenty using podman-compose up -d
* Then tried to login. I Then get this error:
I did a database dump again now and diffed with the old one.
This is the diff:
Do I need to restore the original db dump? Or is my issue unrelated to this?
On further inspection, it seems to me none of these differences have any major relevance. The first ones are just comments (I edited those out). The last ones are real differences, but they seem to only be some app tokens....
You need to restore a
0.51
backup of your database while changing the TAG to 0.51
@prastoin : I think this is what I did.
So: before I did the upgrade earlier. That is, before I changed anything and while I had a working twenty 0.51 instance, I did a database backup using pg_dump.
I have saved that sql file.
Then I did the upgrade/pull and got the 0.55 and broke my deployment.
NOW what I have done is:
podman-compose down
Went into my .env and changed TAG to TAG=0.51
podman-compose pull
podman-compose up -d
Do you mean I have to recover the original backup into my database now?
Indeed you need to restore the dump 0.51 when being in the 0.51 version
Then start incrementally upgrading to 0.55
Right. Will try that.
Wow. That failed spectacularly: https://privatebin.net/?643f0aecd9f424a7#FQ29PUfZnVhDMjqavz2X5GwZRgNnJeBgdSs7x1hbbZxn
PrivateBin
Encrypted note on PrivateBin
Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.
Lots of errors.
I tried following instructions to restore the dump from the Upgrade instructions: on https://twenty.com/developers/section/self-hosting/upgrade-guide
I guess the dump has to delete the db objects before loading?
Please drop your existing database before restoring
So just run:
podman exec -i twenty-db psql -U twenty
Then drop database twenty ??
I did DROP DATABASE twenty; CREATE DATABASE twenty;
Then ran this:
cat databases_backup.sql | time podman exec -i twenty-db psql -U twenty
I now brought back up twenty... Then try to login. I get this error:
column User__User_workspaces.defaultAvatarUrl does not exist
You need to drop twenty database before restoring it
If you don't you will face conflicts as you just did
@prastoin so, if I drop the db, I get this error when trying to load:
$ cat databases_backup.sql | time podman exec -i twenty-db psql -U twenty
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "twenty" does not exist
podman exec -i twenty-db psql -U twenty 0,04s user 0,02s system 44% cpu 0,153 total
IF I create the database and then run it, then I will end up with an empty databse....
This is strange because the dump seems to have this line:
CREATE DATABASE twenty WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.utf8';
To create the db
IF I create the database and then run it, then I will end up with an empty databse....Any errors in logs ?
This is the full output:
$ cat databases_backup.sql | time podman exec -i twenty-db psql -U twenty
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "twenty" does not exist
podman exec -i twenty-db psql -U twenty 0,04s user 0,03s system 33% cpu 0,192 total
From the restore.
Not sure what logs to look for
Please create an empty database twenty
I mean, I can delete that role... But then I will not be able to connect and do the restore....
So I guess this is a bootstrap problem...
This is how it looks after I have loaded the backup:
$ podman exec -it twenty-db psql -U twenty -d template1
psql (16.9 (Debian 16.9-1.pgdg120+1))
Type "help" for help.
template1=# \c twenty
You are now connected to database "twenty" as user "twenty".
twenty=# \d
Did not find any relations.
twenty=# \dt
Did not find any relations.
twenty=# \z
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+------+-------------------+-------------------+----------
(0 rows)
twenty=#
You can edit your dump file manually for not having to create the role
Or adapt your psql/pg_restore command in order to handle conflicts smoother
OK. I edit the dump file and:
commented out the CREATE ROLE statement and the CREATE DATABASE statement;
Then I DROPped the twenty database and recreated it using the CREATE DATABASE statement from the script. Then re-ran the restore. It went without any problems. I have now restarted twenty.
I then go do twenty in my browser.
When I try to login, I get this error:
column User__User_workspaces.defaultAvatarUrl does not exist
When I connect to the database, it seems to be empty:
This is strange because the recovery did load the dump. But not sure where it loaded it to then....
Ah! It is NOT empty. It is just not in the public schema:
It seems that the column that it complains about not existing is indeed existing:
`

Is there somewhere I can query the database to figure out what version it thinks it is?
Everything should be within your
default
database
not public one
Or maybe you were talking about postgres user
Your workspace version is at
default.core.workspace.version
Well, the data is loaded now...
Yes, I see it is 0.51.1
And I have redeployed twenty using TAG=0.51
Perfect
So all should be good, right?
In theory yeah
But still cannot login
Please share both the ui and server error
UI error: column User__User_workspaces.defaultAvatarUrl does not exist
also run in your twenty-server container
yarn command:prod cache:flush
server error is from the container logs?
Is your server up ?
Yes, the server is up
Ah. It is not the -db pod
Is it healthy ? Are you able to hit its healtz endpoint ?


I dont know about healtz endpoint? What does this mean?
Your server is not healthy
Was I supposed to run "podman exec -it twenty-server yarn command:prod cache:flush" somewhere during my upgrade? or after the db reload?
I'm afraid the dump you have did not contain everything such as enums and extensions 🤔
Does not seem related right now
Not sure if you can see all my messagse. I get these errors from discord bot "Clyde":
Your message could not be delivered. This is usually because you don't share a server with the recipient or the recipient is only accepting direct messages from friends. You can see the full list of reasons here: https://support.discord.com/hc/en-us/articles/360060145013
It surprises me that the server is not healthy.... But not sure what to do about it or why it happened.
Maybe I just need to restart the containers?
could you please run in your twenty-server
Yes restarting won't harm
migrate:prod gave:

yarn command:prod upgrade

Are you you recovered the correct dump ?

Looks like you've recovered a dump from after the 0.55 migrate
Oh yes, I am sure it is the correct dump. Why am I sure? Because the core.workspace said version=0.51.1
Unrelated
You have database versioning ( migrate ) and workspace versioning ( workspace version )
OK
The workspace upgrade is protected by the workspace version in database
What's your dump creation date please ?
I no longer have the dump date because I made a copy of the dump to databases_backup.sql.orig before I changed the original dump to not create the databse and role:

databases_backup2.sql is the dump made AFTER the upgrade
Could you please inspect your restored database core schema
and list all its tables
Would it help if I delete my containers and the volumes and then recreate for version0.51 and then load the dump?
Sure
Indeed this is a good idea, but you will have to hack through your dump file a bit
Also we need, in the first place, to assure your dump integrity
Not sure where to put the schema dump?
Is it typeorm_migrations we need?

I have restarted the containers... I have not tried deleting/recreating them yet as I am not sure if we expect this to have any effect.
Hmm... One thing I just notice when I restart the pods:
What do you mean ?
Yes

It says twenty:latest
Could you please inspect your restored database core schema and list all its tables
So maybe it is ignoring my TAG=0.51 in .env?
`
in your twenty-server
Huh?
So it is ignoring .env?
If I do
podman-compose down ; podman-compose pull; podman-compose up -d
then it should be running the twenty containers corresponding to the version specified in TAG=, right?
The upgrade guide says:
We recommend consuming major.minor version such as 0.53So I guess it is not because I need to specify 0.51.1, right? Is it because I need TAG=v0.51 ? (ie. adding the v?) If this is the case, then it does not correspond to what the upgrade docs are saying.... But I have sometimes seen some apps requiring the v be included in the version spec?
You can find docker hub versioning here https://hub.docker.com/r/twentycrm/twenty/tags
Sometimes it does not relate the github tags
docker compose down all your containers
after changing the tag
and docker-compose up them back
The tags seem to include the v
Would be good to have the upgrade docs fixed to include this...
So now I have changed the tag to TAG=v0.51
Should I just do: podman-compose down ; podman-compose pull; podman-compose up -d
?
And then restore the db from backup perhaps? Or no?
To include what ?
Yes please restore once we've verified the APP_VERSION in your twenty-server
To include the v in TAG:
https://twenty.com/developers/section/self-hosting/upgrade-guide

It should say "We recommend consuming "v$major.$minor" version such as
v0.53
" or something like thatWell, this is odd:

This is after I did change TAG=v0.51 and then did the down ; pull; up
Idk for podman but providing the wrong tag fails for docker-compose
Do I perhaps need to be more specific, like TAG=0.51.1 ?
Will update the docs on the fly
no
Sorry TAG=v0.51.1 ?
Should not have an impact
But as your current workspace version is v0.51.1 would still use this version
I found the problem!
Or at least: I found out why TAG was not in effect
There was an issue in the podman-compose.yml which made it ignore it. I have fixed this now.
It is starting up
Fails to start:
Congrats !
If could you please share the issue so it could help other podman user, would be lovely !
Yes, I will.
But I think the issue is not resolved, though. Just the stuff with it keeping getting the :latest version instead of TAG.
But it fails to start and I have no idea why.
It gives some error with unknown manifest?
The issue was that in podman-compose.yml, it would say
image: docker.io/twentycrm/twenty:latest
insteaf of image: docker.io/twentycrm/twenty:${TAG}
and so on
I guess the issue is that I added the TAG value to all images but it does not exist for redis image. So I reverted that to :latest.Now I am able to get furhter in the app. When I log in, I get to the next step after username. I then enter password and now I get this error:

What would be a good next step from here?
Hello could you please double check the following:
- twenty server is on the correct version
- share your
core
schema tables
in your just restored databaseHow do check server version?
echo $APP_VERSION
in twenty-server/app/packages/twenty-server $ echo $APP_VERSION
v0.51.14
How do I send the dump?
core schema dump
Please do not share your dump
Just the list of the tables
Of the successfully restored database
What is the easiest way to get just the list of tables from core schema?
Connecting to your twenty-db container and using psql
Like this?
Yep ! if you could please list all the rows
So not just core.*?
Ah sorry my bad looks good ok
You should be able to start the upgrade on a good basis !
But shouldnt I be able to login into the app now?
Are you facing this ?
Yes
But first time I get THIS error:

Perhaps it is just repeated error twice....
Should I not be able to log in now?
Yes. This is my current state.
It is not clear to me whether this is expected and I should proceed with incremental upgrade. Or this is a problem and I should fix this before procedding.
If you workspace version is 0.51.14 you should not have an issue
please run a in your twenty-server
Before upgrading incrementally I would recommend having a stable twenty instance
Have you cleared the cache also ?
I have run yarn database:migrate:prod. It did not produce errors
After this, I am able to log in to the app
Does this mean that I am now on a working 0.51 state? And I can proceed with incremental upgrade?
After double checking that your workspace version is equal to your 0.51 twenty instance yes !
How do I check this?
Is it this?

Or is that not a sure check?
Or this?

default.core.workspace.version
=== workspace version
APP_VERSION
in twenty-server === Twenty instance versionNot sure what this means?
I need to get this from the DB ? default.core.workspace.version
this
I do not have schema "default". But I have this:

So I guess 0.51.1 != 0.51.14
But not sure if that third number is critical?
By definition it should not be critical as upgrade commands should never be added to a patch version
You can go for 0.52
please always pick the latest patch version
or directly v0.52
OK. So I am good to proceed with inc. upgrade from 0.51 -> 0.52? Correct?
Sorry, but this is a bit confusing for me and I am a bit afraid to mess this up again....
Yes you should be good !
No worries, and now you know how to restore to the 0.51 in case
I would recommend making a dump at each versions
A database dump?
Or also dump other stuff?
Thanks for confirming
$ podman exec -it twenty-db pg_dumpall -U twenty > databases_backup-v0.51.1-$(date -I).sql
You're welcome
I think it would make sense to update the upgrade guidelines based on what we found here:
1: TAG must include "v" in the version spec. E.g. v0.51 and NOT 0.51
2: The instructions to backup/restore database does not work due to missing handling of db/role creation. There should be instructions on how to manually DROP DATABASE and coment out CREATE DATABASE and CREATE ROLE statements from the dump
I think I have successfully upgraded to 0.52 but how do I verify?
I have completed running:
yarn database:migrate:prod
yarn command:prod upgrade
No errors.
Do I just login to the app?
Is the verification to log in to the app and open admin panel?

Check workspace version and twenty version
And following related upgrade guide docs https://twenty.com/developers/section/self-hosting/upgrade-guide
$ echo 'echo $APP_VERSION; exit' | podman exec -i twenty-server /bin/sh
v0.52.11
$ echo 'SELECT version FROM core.workspace;' | podman exec -i twenty-db psql -U twenty
version
---------
0.52.11
(1 row)
Looks good
Please note that

OK. So since I am using podman, I guess I will have to figure out what was changed in the Dockerfile such that I can update my podman
I'm not sure to understand
The dockerFile is used to built the image you will be pulling from the docker hub
You don't have anything to do
Ah. I see!
Sorry, I was thinking of docker-compose.yml
No worries all good !
But indeed on any docker compose yml file the update has to be done manually
( not the case here )
So basically to get to 0.53, I just have to stop twenty; change .env TAG=v0.53 ; start twenty ; that is it?
Then I can repeat for 0.54; and so on?
So I wanted to do this. And for that I wanted to do the db backup. But it fails:
No. The db backup is not what fails. Sorry.
The getting version from twenty instance is.
This is what happens when I need to get the version by getting a shell on the instance:
´
If I try to open the app in a browser, I get 502 Bad Gateway
So perhaps the upgrade to 0.53 did not go well afterall?
Restarted containers and now it works... strange....
trying upgrade again....
I think it succeeded:
~/apps/twenty $ echo 'SELECT version FROM core.workspace;' | podman exec -i twenty-db psql -U twenty
version
---------
0.55.9
(1 row)
~/apps/twenty $ echo 'echo $APP_VERSION; exit' | podman exec -i twenty-server /bin/sh
v0.55.9
YAY!
Thank you @prastoin for your help!
Congrats @EbenezerIbiza !
You're welcome !