fix(migrations): explicit id + enum cast for 0024 backfill
- mesh.topic.id has no PG-side default (drizzle $defaultFn is ORM-only) - mesh.topic_member.role needs an explicit cast to the enum type Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,13 @@
|
||||
-- Idempotent — safe to re-run. The unique indices on (mesh_id, name) and
|
||||
-- (topic_id, member_id) make the inserts no-ops on the second pass.
|
||||
|
||||
INSERT INTO mesh.topic (mesh_id, name, description, visibility)
|
||||
-- mesh.topic.id has no Postgres-side default (drizzle's $defaultFn runs
|
||||
-- only via the ORM), so generate a 32-char lowercase-hex id from a v4
|
||||
-- UUID with dashes stripped. gen_random_uuid is built into Postgres 13+
|
||||
-- so no pgcrypto extension required.
|
||||
INSERT INTO mesh.topic (id, mesh_id, name, description, visibility)
|
||||
SELECT
|
||||
replace(gen_random_uuid()::text, '-', ''),
|
||||
m.id,
|
||||
'general',
|
||||
'Default mesh-wide channel. Every member can read and post.',
|
||||
@@ -26,7 +31,7 @@ INSERT INTO mesh.topic_member (topic_id, member_id, role)
|
||||
SELECT
|
||||
t.id,
|
||||
mm.id,
|
||||
CASE WHEN m.owner_user_id = mm.user_id THEN 'lead' ELSE 'member' END
|
||||
(CASE WHEN m.owner_user_id = mm.user_id THEN 'lead' ELSE 'member' END)::mesh.topic_member_role
|
||||
FROM mesh.topic t
|
||||
JOIN mesh.mesh m ON m.id = t.mesh_id
|
||||
JOIN mesh.member mm ON mm.mesh_id = t.mesh_id AND mm.revoked_at IS NULL
|
||||
|
||||
Reference in New Issue
Block a user