GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position"
Testing upgrade from 0.3.0 to 0.3.1 we get this error.
I have added the field "position" to company/people/opportunities but I am still getting it. I suspect it might be an issue with updating the TypeORM layer but I am not sure if this is the actual issue.
Is there a way to add this Field and continue with the current data?
86 Replies
Hi @๐
น๐
ฐ๐๐
ฑ๐
ด๐
ด, so it's not documented yet as this is super experimental but you can play with workspace:health (to make sure your workspace postgres schema is a healthy state compared to your metadata) and workspace:sync-metadata commands to upgrade it to the latest stages.
I'm quite sure this won't fully work but it should help
I'm interested into helping your migrate to the new version to see how good/bad the tooling is right now
Could you start by giving me the output of
npx nx command -- workspace:health -w {YOUR_WORKSPACE_ID} -d
? (it should write some logs into /logs folderShould there be something after -d?
nope
the -d is not properly named (it's dry-run but it should actually be something like --verbose)
Cannot find project 'workspace_6zezc5oiagj6yqldcepfgb226'
Cannot find project '{workspace_6zezc5oiagj6yqldcepfgb226}'
you need to put your workspace.id
not your workspace schema name
Ah, apologies
no worries, it's not documented so... ๐
Where do I find the id? I've seen it but can't remember where
Is it on the invite screen?
you'll need to either check it in your database, or in your nework table /graphql responses (you should see some information about the currentWorkspace and its id)
Found the id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e but no metter how I write it I get "Cannot find project"
Should the {} be there or was that your way of stating <insert-here> ?
was my way of saying insert there
Cannot find project '75f6e77a-ec52-43fd-af2b-5e1ca8319b2e'
You need to be in the server folder to execute it
~/dev/twenty/twenty/packages/twenty-server > npx nx command -- workspace:health -w 20202020-1c25-4d02-bf25-6aeccf7ea419 -d
[Nest] 58070 - 03/15/2024, 3:38:05 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 1 issues
[Nest] 58070 - 03/15/2024, 3:38:05 PM LOG [WorkspaceHealthCommand] Issues written to logResetting our test-env to see if my trying to fix it has broken the broken state ๐
No difference after reset
sorry, my bad, you need to add a space after --
Ah ofc!
you can also run it directly (without nx) if you haven't made any modification by running
yarn command workspace:health
nx is meant for dev mode and yarn command for prodWorkspace is not healthy, found 10 issues
ugh
ok not so bad :p
Was more the formatting I was annoyed at ๐
yeah ๐ that's why we are not bragging about it
could you paste the output of workspace-health-issues-75f6e77a-ec52-43fd-af2b-5e1ca8319b2e.json ?
Ok
Have you made a dump of your database?
Yes
we will try to fix it (it should not destroy anything but let's be super safe)
Ok
Don't worry we have test-env
ok ๐
Let's try:
yarn command workspace:health --workspace-id {your_workspace_id} --fix default-value
(running prerelease 0.x software is bad enough :))
we have stabilized the way we handled default-value in 0.3.2 so the health check detects some issue in previous previous versions. This command should fix most of them
Ah this is 0.3.0-> 0.3.1 should I reset and try 0.3.0->0.3.2 directly?
yes you can go to 0.3.2 directly
I can guide you through the breaking changes
we are releasing 0.3.3 this week-end or on Monday (we are releasing every two weeks)
The migration scripts (yarn database:migrate) are automatically run btw if that messes with this process (I'm assuming it shouldn't but worth pointing out)
yep, these should not be a problem
yarn command workspace:health --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e --fix default-value -d
Usage Error: Couldn't find a script named "command".
package.json looks different I think - not sure
yep
replace
yarn command
by node dist/src/command.js
module not found
are you on twenty-server folder?
yes
do you have a dist folder? (I'm not sure what's your setup)
No, using the prebuilt docker images you provide
weird, i'm quite sure there is a dist folder in the prebuilt-docker image
CMD ["node", "dist/src/main"] (that's the command that is launched at the end of the dockerfile)
You are correct.
It's user error. Fixing it
ok ๐
Workspace is not healthy, found 37 issues
ok could you paste the output?
same file
Ok, so you have the 10 issues because of defaultValue + 27 because we also have clarified the delete onCascade behaviors
for the first one we have a fix command (the one I gave you earlier) that you can run. For the other one we are going to ignore it for now and get back to it later
But shouldn't the 10 issues disappear when i run with --fix default-value?
Ah removing -d (dryrun-ish) fixed them
ok cool
This repeats though if I run it again
ok
So I 'm not sure the fix is comitted
let's run the health check without --fix again and see if we only have 27 issues?
Nope stays at 37
ok weird
give me 1 sec
"[Nest] 750 - 03/15/2024, 3:48:47 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 37 issues
Segmentation fault (core dumped)
"
This seems bad
ok, let's ignore these for now I don't want to invest into fixing it as they might be fix by the upgrade
Ignoring for now!
So, let's move to the next step of the process and get back to the health check later
can you do:
node dist/src/command.js workspace:sync-metadata --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d
(here the -d is important as it will enable us to check what's going to happen)
The idea is to migrate a given workspace to the last version of Twenty schema
then we should have a new folder in logs
Issues found - aborting. Should I --force?
yes!
logs created
ok, could you send me the files?
actually, just the delete ones?
the other are not worrying :p
Easier to pack them all
looks good
let's run it without -d
I can see our data again!
wonderful!
let's run the health-check again ๐
18 issues
looks reasonable, could you paste the output?
ok! So we still have mismatch between what's in metadata.relationMetadata table and what we have in our workspace postgres schema
metadata.relationMetadata is up-to-date and the health check is saying: be careful the onDelete behavior is different
so what you need to do is to manually go to each of these foreign keys and update the onCascade in your postgres preferred UI / cli
the easiest way to get to know what to update is to take a look at the "columnStructure" + "relationMetadata" fields
For example for the first one:
"relationMetadata": {
"id": "8ebdd390-cd55-431e-9f27-5034f6d93f0c",
"relationType": "ONE_TO_MANY",
"onDeleteAction": "SET_NULL",
"fromObjectMetadataId": "c3643370-d13a-4f97-aece-6b429df5ee98",
"toObjectMetadataId": "22426d48-9f33-4f08-8039-14d409186aab",
"fromFieldMetadataId": "6d7a8099-c411-4284-a9ee-10c3ec3b52f1",
"toFieldMetadataId": "fec30d5d-6b1c-4705-bc15-02d4f06890e2",
"workspaceId": "75f6e77a-ec52-43fd-af2b-5e1ca8319b2e",
"createdAt": "2024-01-30T11:06:04.896Z",
"updatedAt": "2024-01-30T11:06:04.896Z"
},
"columnStructure": {
"tableSchema": "workspace_6zezc5oiagj6yqldcepfgb226",
"tableName": "activityTarget",
"columnName": "activityId",
"dataType": "uuid",
"isNullable": true,
"columnDefault": null,
"isPrimaryKey": false,
"isForeignKey": true,
"isUnique": false,
"onUpdateAction": "NO ACTION",
"onDeleteAction": "CASCADE"
},
It means that activityTarget.activityId FK is set as NO_ACTION in your postgres workspace schema VS SET_NULL in your metadata.relationMetadata ==> you should set it to SET_NULL
once done, your workspace should be healthy!
Ideally in the next releases, your workspace will keep being healthy and you'll just have to run the sync-metadata command and that's it!
Will do. After each release I should do migrate+sync metadata or just sync?
typeorm:migrate (this will migrate everything except the workspace schemas) + sync-metadata
@charles I got almost all the way. I believe I managed to fix all the relations (no more errors) but we have created a object (type?) called Key/Keys that a company can have 0..N of. When I try to access this "Keys" object I get:
`
Workspace is reporting "Healthy" though.
I think you are missing a "position" field of type POSITION on your Key object
this should be captured by the sync-metadata, can you dry run the sync-metadata again and give me the output of fields-create, and fields-update?
node dist/src/command.js workspace:sync-metadata --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d
gives empty files in logs/sync-work...
cat logs/sync-workspace-logger-service/*
[][][][][][][][][][]
you are on 0.3.2 right?
yes, might I be missing a restart or something simple?
I am not sure
Could you look into your workspace schema and see if you have a position column on your key table?
No it's not there
`
we might have an issue with our sync scripts for custom objects. We will dig into it tomorrow
in the mean time if you don't have any important data into this table, you might just want to drop it and create a new object
it should have the position field
I think there was a bug that should be fixed in 0.3.3 released tomorrow but I'm unsure
Can I just drop table in postgres or do I need to go through UI?
Ah I found the ui for it now. Had to deactivate first
I ยดll just drop and recreate if we go forward in using it. Until then it can stay until 0.3.3 for a possible bug report
Thank you for your help
You are welcome!