keygen-sh / keygen-api

Keygen is a fair source software licensing and distribution API built with Ruby on Rails. For developers, by developers.
https://keygen.sh
Other
700 stars 40 forks source link

Account.create! issuing UPDATE statement rather than INSERT #805

Closed thefringeninja closed 3 months ago

thefringeninja commented 3 months ago

I am running the setup rake task but no account is created when it completes. I turned on postgresql logging and this saw this:

LOG:  execute <unnamed>: SELECT "roles".* FROM "roles" WHERE "roles"."id" = 'ce09cd82-c550-41d4-b592-33faeba0d994' LIMIT 1
LOG:  execute <unnamed>: UPDATE "accounts" SET "updated_at" = '2024-04-02 17:06:51.474011' WHERE "accounts"."id" = '64c0885b-cc3e-446b-bced-662162eca7d3'
LOG:  statement: COMMIT
LOG:  execute <unnamed>: SELECT "users".* FROM "users" INNER JOIN "roles" ON "roles"."resource_type" = 'User' AND "roles"."resource_id" = "users"."id" WHERE "users"."account_id" = '64c0885b-cc3e-446b-bced-662162eca7d3' AND "roles"."name" = 'admin' ORDER BY "users"."created_at" DESC LIMIT 1

Although I can see here that it's calling create! which afaik should always result in an INSERT statement.

ezekg commented 3 months ago

Share your entire log file, please. Sharing 4 lines is not helpful. There are multiple places where an account can be updated during the account creation flow. Regardless, the update would fail if the account didn't exist (as would all the other inserts, e.g. roles, users, etc. since they depend on an account foreign key), so this points to a deeper issue in your setup run.

thefringeninja commented 3 months ago

You were right, further up the log I see that insert statements were indeed executed. When I changed the database name it worked.