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 <noreply@anthropic.com>
This commit is contained in:
@@ -37,19 +37,21 @@ def upgrade() -> None:
|
|||||||
# 1. Pages with calendars -> features={"calendar": true}
|
# 1. Pages with calendars -> features={"calendar": true}
|
||||||
conn.execute(text("""
|
conn.execute(text("""
|
||||||
INSERT INTO page_configs (post_id, features, created_at, updated_at)
|
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
|
FROM posts p
|
||||||
JOIN calendars c ON c.post_id = p.id
|
|
||||||
WHERE p.is_page = true
|
WHERE p.is_page = true
|
||||||
AND p.deleted_at IS NULL
|
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}
|
# 2. Market page (slug='market', is_page=true) -> features={"market": true}
|
||||||
# Only if not already inserted above
|
# Only if not already inserted above
|
||||||
conn.execute(text("""
|
conn.execute(text("""
|
||||||
INSERT INTO page_configs (post_id, features, created_at, updated_at)
|
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
|
FROM posts p
|
||||||
WHERE p.slug = 'market'
|
WHERE p.slug = 'market'
|
||||||
AND p.is_page = true
|
AND p.is_page = true
|
||||||
@@ -60,7 +62,7 @@ def upgrade() -> None:
|
|||||||
# 3. All other pages -> features={}
|
# 3. All other pages -> features={}
|
||||||
conn.execute(text("""
|
conn.execute(text("""
|
||||||
INSERT INTO page_configs (post_id, features, created_at, updated_at)
|
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
|
FROM posts p
|
||||||
WHERE p.is_page = true
|
WHERE p.is_page = true
|
||||||
AND p.deleted_at IS NULL
|
AND p.deleted_at IS NULL
|
||||||
|
|||||||
Reference in New Issue
Block a user