strinking / statbot

A data ingestion bot that reads records from Discord guilds into a SQL database.
MIT License
22 stars 5 forks source link

Relax foreign key constraints on Audit logs and reactions #72

Open theKAKAN opened 1 year ago

theKAKAN commented 1 year ago

The problem happens when a user has added some reaction, or has their ID in the audit log, but have left the server. In that case, we get a bunch of errors of foreign key violations because the user doesn't exist in the users table. I'm not sure if the better way is to remove foreign key, or just create a dummy "Unknown user" in the users table...

psycopg2.errors.ForeignKeyViolation: insert or update on table "audit_log" violates foreign key constraint "audit_log_int_user_id_fkey"
DETAIL:  Key (int_user_id)=([REDACTED]) is not present in table "users".

sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) insert or update on table "reactions" violates foreign key constraint "reactions_int_user_id_fkey"
DETAIL:  Key (int_user_id)=([REDACTED]) is not present in table "users".