Refresh test schema to match current platform schema - #16
Merged
Conversation
The hand written test schema had drifted from the actual platform schema. Columns which are present now match their real definitions in name, type and nullability: * auth_user is now users_user * msgs_msg.quick_replies is now quickreplies jsonb * add flows_flowstartcount which we delete from when deleting orphaned starts * fix nullability of flows_flowrun.session_uuid, flows_flowrun.results and msgs_msg.next_attempt * use uuid type for uuid columns which are no longer varchar * use bigint/bigserial for ids which are no longer integer * fix varchar lengths on name and attachment columns * add missing non-null columns and foreign keys * remove drops for tables which are never created
Review SummarySolid, well-documented change — this is a schema-only refresh of the
One gap (also acknowledged in the PR notes): the newly-added No blocking issues. |
The fixture's only flow start had a run attached, so the orphan deletion path in DeleteFlowStarts never executed and the tables it deletes from were never validated. Add an old start with no runs, along with its contact, group and count rows, and assert they're all deleted while a start which still has a run is not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The hand written
testdb.sqlused by the test suite had drifted from the platform schema it's meant to mirror. Since it's only a subset of that schema, drift is easy to miss — but a column that's misnamed, wrongly typed, or has the wrong nullability means the tests can pass against a shape that doesn't exist in production.Refreshed it against the current schema. The rule is now stated at the top of the file: it stays a minimal subset (only the tables and columns archiver reads from or deletes from), but any column that is present must match its real definition exactly.
Changes
Renamed or removed upstream:
auth_userno longer exists — replaced withusers_user(username→email)msgs_msg.quick_replies varchar(64)[]→quickreplies jsonbflows_flowstartcount, whichDeleteFlowStartsdeletes from but which was missing entirelyDROP TABLElines forchannels_channellog(no longer exists) andivr_call(never created here)Nullability, two of which were inverted:
flows_flowrun.session_uuidis NOT NULL,flows_flowrun.resultsis nullablemsgs_msg.next_attempt,msgs_broadcast.is_active,contacts_contact.created_by_idandmodified_by_idare all nullableTypes:
uuidrather thanvarchar(36)onchannels_channel,flows_flow,contacts_contactgroup,msgs_label(contacts_contact.uuidis genuinely still a varchar)bigint/bigserialonarchives_archive.idandrollup_id,flows_flowrun.id,msgs_label.id,msgs_msg_labels.*,msgs_broadcast.schedule_id,msgs_broadcastmsgcount.countand the m2m table idsmsgs_msg.attachmentsisvarchar(2048)[]orgs_org,channels_channel,flows_flow,contacts_contactgroupAlso added the non-null columns needed to keep the fixture coherent (
msgs_label.org_id,flows_flowstart.flow_id/uuid/start_type/status/modified_on,msgs_broadcast.base_language,msgs_broadcastmsgcount.is_squashed) plus the foreign keys onarchives_archive.org_idandrollup_id.Coverage for orphaned flow start deletion
The reason the missing
flows_flowstartcounttable went unnoticed is that its delete path never ran: the fixture's only flow start had a run pointing at it, so theNOT EXISTSguard inDeleteFlowStartsnever selected anything and theDELETE from flows_flowstartcountstatement never executed.Added flow start #2 for org 3 — old enough to be past the retention threshold, with no runs pointing at it — along with its contact, group and count rows, and an org 3 contact group for it to reference.
TestArchiveOrgRunsnow asserts all four rows are deleted while start #1, which still has a run, survives.Test plan
go test -p=1 ./...passes.information_schema.columnsfor the loaded test schema against the real one — every column present matches on name, type, length and nullability.flows_flowstartcountcount expectation to 1 and confirmingTestArchiveOrgRunsfails, so the delete really is executing rather than the row never having existed.