{"record":{"id":"3f8d7c5747e2f75d","repo":"block/buzz","slug":"seed-canonical-admin","errorCode":null,"errorMessage":"seed canonical admin","messagePattern":"seed canonical admin","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/buzz-db/src/store/channel_members.rs","lineNumber":3166,"sourceCode":"        let community_uuid = Uuid::new_v4();\n        let community = CommunityId::from_uuid(community_uuid);\n        let channel = Uuid::new_v4();\n        let relay_keys = Keys::generate();\n        let owner_keys = Keys::generate();\n        let owner = owner_keys.public_key().to_bytes();\n        seed_community_channel(&pool, community_uuid, channel, &owner_keys).await;\n        let member = Keys::generate().public_key().to_bytes();\n        sqlx::query(\n            \"INSERT INTO channel_members (community_id, channel_id, pubkey, role, invited_by) \\\n             VALUES ($1, $2, $3, 'admin', $4)\",\n        )\n        .bind(community_uuid)\n        .bind(channel)\n        .bind(member.as_slice())\n        .bind(owner.as_slice())\n        .execute(&pool)\n        .await\n        .expect(\"seed canonical admin\");\n\n        let roster = |role: &str, timestamp| {\n            EventBuilder::new(Kind::Custom(39002), \"\")\n                .tags(vec![\n                    Tag::parse([\"d\", channel.to_string().as_str()]).expect(\"d tag\"),\n                    Tag::parse([\"p\", hex::encode(owner).as_str(), \"\", \"owner\"])\n                        .expect(\"owner p tag\"),\n                    Tag::parse([\"p\", hex::encode(member).as_str(), \"\", role])\n                        .expect(\"member p tag\"),\n                ])\n                .custom_created_at(Timestamp::from(timestamp))\n                .sign_with_keys(&relay_keys)\n                .expect(\"sign roster\")\n        };\n        let base = Timestamp::now().as_secs();\n        let fresh = roster(\"admin\", base);\n        assert!(\n            db.replace_addressable_event(community, &fresh, Some(channel))","sourceCodeStart":3148,"sourceCodeEnd":3184,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/crates/buzz-db/src/store/channel_members.rs#L3148-L3184","documentation":"The test seeds the canonical owner row by INSERTing the community/channel/member/owner binding into the scratch database. The expect panics when the INSERT fails — typically a foreign-key violation (referenced community/channel rows absent), a NOT NULL/unique constraint, or RLS/check constraints rejecting the seed values.","triggerScenarios":"INSERT into the roster/channel_members table when the parent channel or community row does not exist yet (FK violation), the member already has a row (unique violation), or a CHECK constraint on role/name fails.","commonSituations":"Executing the seed before the schema's prerequisite inserts; schema.sql in the scratch DB missing seed DML that production bootstrap applies (per AGENTS.md, pgschema and raw schema application differ); column list drift after a migration added a NOT NULL column.","solutions":["Insert prerequisite community/channel rows before this seed INSERT","Read the sqlx constraint-violation error to see which FK/unique/CHECK failed and satisfy it","Compare the INSERT's column list against the current table schema after recent migrations","If RLS policies apply, run the seed as the table owner or bypass RLS role"],"exampleFix":"// before\n.bind(owner.as_slice())\n.execute(&pool).await.expect(\"seed canonical admin\");\n// after\n.bind(owner.as_slice())\n.execute(&pool).await.unwrap_or_else(|e| panic!(\"seed canonical admin: {e} — are the community/channel prerequisite rows present?\"));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":".execute(&pool).await\n    .unwrap_or_else(|e| panic!(\"seed canonical admin failed: {e} — check FK parents and unique constraints\"));","preventionTips":["Insert parent community/channel rows before member seeds","Match the INSERT column list to the live table after migrations","Run seeds as a role that bypasses RLS or is table owner"],"tags":["postgres","sql","foreign-key","test-infrastructure"],"backgroundTag":"foreign-key-violation","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-08-30T13:49:18.474Z","contentChangedAt":"2026-08-30T13:49:18.474Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}