Skip to content

fix(events): record who created each event, and delete accounts without a foreign-key error - #564

Merged
mindsers merged 11 commits into
mainfrom
fix/event-origin
Nov 19, 2026
Merged

mindsers merged 11 commits into
mainfrom
fix/event-origin

Conversation

@mindsers

@mindsers mindsers commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR 0d of the event schedules plan (#533): Event.origin (T10), and account deletion no longer failing.

Why

An empty meeting the recurring-events job created ahead was recognised by having no author. Only those move with their template when its day changes, or go with it when it is deleted. But deleting an account must clear the author of what it created, and then a hand-made event would have looked exactly like one of the job's. So deleting an account could not be fixed until "made by the job" was recorded on its own.

What changes

  • Event.origin: job, manual or import. It has a CHECK constraint and defaults to manual. The migration gives job to events without an author and with nothing on them (no part, service or counts), which is exactly what an empty meeting was until now.
  • Every check reads the origin. That covers EMPTY_MEETING and the three inline copies of the rule (time-zone re-anchoring, the import clean-up, the template page count), plus the series' empty-meeting test.
    • The job writes job.
    • Preparing a job meeting's programme, from « Créer le programme » or a series, or moving it by hand, makes it manual.
    • The author now only says who prepared it.
    • Both programme paths name whoever fills a meeting that has no author. Only a job meeting changes origin.
    • A series skipping a day re-checks, in the delete itself, that the meeting there is still the job's empty meeting.
  • Account deletion no longer ends in a foreign-key error on Event.createdById, the only restricting key to UserAccount. This covers both paths that delete an account: Réglages › Utilisateurs, and « Retirer la connexion » on a publisher record. Both go through one helper, releaseAccountEvents.
    • An account without a record takes its absences with it. It can't have flagged any assignment, since absences flag through the record.
    • Its other events lose their author and keep their origin, so a hand-made one stays where it is.
    • An account linked to a record that has absences is refused with a toast: « Ce compte a des absences : elles restent avec la personne, il ne peut pas être supprimé pour l’instant. » Its absences will be handed to the record in PR 1. On « Retirer la connexion », the refusal gets its own message instead of the last-administrator one its route used to fall back to.
    • The audit trail keeps which absences went with a record-less account, and how many events lost their author.
  • Archive 2.18: events.ndjson carries origin. A 2.18 archive's origin is kept. In an older archive, an event without an author and with nothing on it comes back as job by the migration's rule, so it still moves with its template; any other event comes back as import. An origin this version doesn't know also comes back as import, with a warning.

Also in this PR, as its own commit: a publisher record's assignments within one meeting (the coming ones and the last one done) now follow the programme's order. They came back in random order, which made personal-views.reference fail at random in full runs.

Rollout

While the new version deploys, the previous one keeps creating empty meetings at the default manual. Those stop moving with their template until a later migration gives them job. That migration must be limited to events created during the rollout: running this one's backfill again as it is would also flip a hand-made event whose author's account was deleted in the meantime. The migration header says so.

References changed on purpose

Event rows read whole gain origin: job on the eleven meetings created ahead, manual on the others, and the same values after a restore. Nothing else moved; the other changed lines are the commas before it.

Verification

  • Migration test on the shipped SQL: only "no author, nothing on it" becomes job (a part, a service, counts or an author each keep manual); idempotent; an unknown origin is refused.
  • Empty meetings:
    • A hand-made empty event without an author is not moved with its template.
    • A job meeting moved by hand, or given its programme, becomes manual. With the switch removed, the test fails.
  • Headline case, end to end: delete the accounts, then change the template's day and delete the template. Their hand-made meetings stay where they are, and the template is refused as in use. With the old "no author" rule put back, this test fails.
  • Account deletion and « Retirer la connexion », as integration tests:
    • without a record: deleted, absences gone, author cleared, origin kept;
    • with a record and absences: refused, nothing changed;
    • with a record and no absences: deleted.
    • The refusal also maps to its message.
  • Archive: carried origins, and the old-archive rule after counts, parts and services are imported, in runImport's order. Also an unknown origin. The two tests that replay runImport run the new step too.
  • Unit (653 files) and integration (121 files, two full runs) suites, lint, typecheck and every architecture gate.

…gramme's order

A record's coming assignments, and the last one done, read several of one meeting in whatever order the table returned them, so the record — and the reference suite — could change from one run to the next. They now follow the programme: parts, then services, each in their order.
Event.origin (job, manual, import; CHECK, default manual). Events without an author and with nothing on them — the empty meetings the recurring-events job created — become the job's.
…missing author

Only the job's empty meetings move with their template or go with it. They were told apart by having no author, but clearing an author — deleting an account — would have turned a hand-made event into one. The job writes « job »; preparing a job meeting's programme or moving it by hand makes it « manual »; every check reads the origin.
…ated

Deleting an account ended in a foreign-key error on any event it had created. An account without a record now takes its absences with it, and its other events lose their author and keep their origin, so a hand-made one stays where it is. An account linked to a record that has absences is refused: « Ce compte a des absences », until they can be handed to the record.
events.ndjson gains origin. A 2.18 archive's origin is kept; an older archive's event without an author and with nothing on it comes back as the job's, by the migration's rule, so it still moves with its template, and any other as « import » — as does an origin this version does not know.
Changed on purpose: event rows read whole gain `origin` — « job » on the eleven meetings created ahead, « manual » on the others, the same after a restore. Nothing else moved: the other changed lines are the commas before it.
« Créer le programme » named the person when an event had no author, the series did not: a hand-made meeting whose author's account was deleted got its programme with nobody named. Both now name whoever fills it, and leave a hand-made meeting's name and hours. Comments that tied a missing author to the job now say what the origin decides.
…he events it created

« Retirer la connexion » deletes the login too, and still ended in the foreign-key error Réglages no longer has. Both now let go of the account's events through one helper: a record's absences refuse it, with their own message rather than the last administrator's; its other events lose their author. The audit trail keeps which absences went with a record-less account and how many events lost their author. A test deletes accounts, then changes and deletes their template: their hand-made meetings stay.
…d leave a restored event's origin

A series passing a day deleted the meeting there on what it had read; the delete now checks it is still the job's empty meeting. « Créer le programme » turned a restored event without an author into « manual », the series did not: both now only change a job meeting's origin, and name whoever prepares an event without an author.
… and replay the step in the round trips

The old-archive rule is checked on a service and on counts as well as a part, in runImport's order, and the two tests that replay runImport's sequence run the new step. The reference fixture names the meetings created ahead by their origin.
The author no longer stands for « made by the job »: the schema says who it names, and when it is null. The migration no longer promises a plain re-run of its backfill — a catch-up must keep to the rollout window. Origin docs say which actions make a meeting « manual » and what « import » covers.
@mindsers
mindsers merged commit 4af9530 into main Nov 19, 2026
7 checks passed
@mindsers
mindsers deleted the fix/event-origin branch November 19, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant