From 3cc57303774039125944f09e41921e2f5848062a Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 10 Feb 2026 14:35:31 +0000 Subject: [PATCH] fix: use jsonb cast and EXISTS in page_configs migration PostgreSQL json type doesn't support equality operators needed by DISTINCT. Use EXISTS subquery instead and cast to jsonb. Co-Authored-By: Claude Opus 4.6 --- .../versions/a1b2c3d4e5f6_add_page_configs_table.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py b/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py index 87d78be..9cb858c 100644 --- a/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py +++ b/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py @@ -37,19 +37,21 @@ def upgrade() -> None: # 1. Pages with calendars -> features={"calendar": true} conn.execute(text(""" INSERT INTO page_configs (post_id, features, created_at, updated_at) - SELECT DISTINCT p.id, '{"calendar": true}'::json, now(), now() + SELECT p.id, '{"calendar": true}'::jsonb, now(), now() FROM posts p - JOIN calendars c ON c.post_id = p.id WHERE p.is_page = true AND p.deleted_at IS NULL - AND c.deleted_at IS NULL + AND EXISTS ( + SELECT 1 FROM calendars c + WHERE c.post_id = p.id AND c.deleted_at IS NULL + ) """)) # 2. Market page (slug='market', is_page=true) -> features={"market": true} # Only if not already inserted above conn.execute(text(""" INSERT INTO page_configs (post_id, features, created_at, updated_at) - SELECT p.id, '{"market": true}'::json, now(), now() + SELECT p.id, '{"market": true}'::jsonb, now(), now() FROM posts p WHERE p.slug = 'market' AND p.is_page = true @@ -60,7 +62,7 @@ def upgrade() -> None: # 3. All other pages -> features={} conn.execute(text(""" INSERT INTO page_configs (post_id, features, created_at, updated_at) - SELECT p.id, '{}'::json, now(), now() + SELECT p.id, '{}'::jsonb, now(), now() FROM posts p WHERE p.is_page = true AND p.deleted_at IS NULL