Hirevo/alexandrie

ERROR: insert or update on table "sessions" violates foreign key constraint "sessions_author_id_fkey"

jerbs opened this issue · 1 comments

jerbs commented

I am getting a foreign key constraint violation when trying to open the Alexandrie frontend in Safari browser. I am using Postgres as database. Database was empty when Alexandrie was was started. Complete Postgres log is attached.

% ./bin/alexandrie
Dec 30 14:45:35.972 INFO starting Alexandrie (version: 0.1.0 - 6e0b901)
Dec 30 14:45:35.973 INFO running database migrations
Dec 30 14:45:36.077 INFO setting up request logger middleware
Dec 30 14:45:36.077 INFO setting up session middleware
Dec 30 14:45:36.077 INFO setting up authentication middleware
Dec 30 14:45:36.077 INFO mounting '/'
Dec 30 14:45:36.077 INFO mounting '/me'
Dec 30 14:45:36.077 INFO mounting '/search'
Dec 30 14:45:36.077 INFO mounting '/most-downloaded'
Dec 30 14:45:36.079 INFO mounting '/last-updated'
Dec 30 14:45:36.079 INFO mounting '/crates/:crate'
Dec 30 14:45:36.079 INFO mounting '/account/login'
Dec 30 14:45:36.079 INFO mounting '/account/logout'
Dec 30 14:45:36.079 INFO mounting '/account/register'
Dec 30 14:45:36.079 INFO mounting '/account/manage'
Dec 30 14:45:36.079 INFO mounting '/account/manage/password'
Dec 30 14:45:36.079 INFO mounting '/account/manage/tokens'
Dec 30 14:45:36.079 INFO mounting '/account/manage/tokens/:token-id/revoke'
Dec 30 14:45:36.079 INFO mounting '/assets/*path'
Dec 30 14:45:36.079 INFO mounting '/api/v1/account/register'
Dec 30 14:45:36.079 INFO mounting '/api/v1/account/login'
Dec 30 14:45:36.079 INFO mounting '/api/v1/account/tokens'
Dec 30 14:45:36.079 INFO mounting '/api/v1/account/tokens/:name'
Dec 30 14:45:36.079 INFO mounting '/api/v1/categories'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/new'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/suggest'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/:name'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/:name/owners'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/:name/:version/yank'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/:name/:version/unyank'
Dec 30 14:45:36.079 INFO mounting '/api/v1/crates/:name/:version/download'
Dec 30 14:45:36.080 INFO listening on '127.0.0.1:3031'
Dec 30 14:45:36.080 INFO Server listening on http://127.0.0.1:3031
Dec 30 14:45:42.255 INFO <-- GET /
Dec 30 14:45:42.285 INFO --> GET / 500 30ms, insert or update on table "sessions" violates foreign key constraint "sessions_author_id_fkey"

postgresql-2021-12-30_000000.log

add following migration:

drop table "sessions";
create table "sessions" (
    "id" varchar(255) primary key,
    "author_id" bigint,
    "expiry" varchar(25) not null,
    "data" text not null,
    foreign key ("author_id") references "authors"("id") on update cascade on delete cascade
);

the issue is that bigserial has the constraint not null. only inserting registered users into the sessions table breaks error messages for not logged in users.