FlexMeasures / flexmeasures

The intelligent & developer-friendly EMS to support real-time energy flexibility apps, rapidly and scalable.
https://flexmeasures.io
Apache License 2.0
133 stars 34 forks source link

Fix audit_log on account deletion #1084

Closed nrozanov closed 3 weeks ago

nrozanov commented 1 month ago

Deleting an account via CLI may not possible as the audit log entries remain: sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) update or delete on table "account" violates foreign key constraint "audit_log_affected_account_id_account_fkey" on table "audit_log" DETAIL: Key (id)=(17) is still referenced from table "audit_log". We need to start deleting audit_log records when affected_account is being deleted. Probably should use 'ON CASCADE' option

Flix6x commented 3 weeks ago

Which PR closed this?

nhoening commented 3 weeks ago

We found that I had not ran the latest migrations (cascading was added later in the audit log PR), so this bug is not existent actually.