From f63a9ec0a7e4c35212fa77b36a57aa4b5a3d8638 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 10 Feb 2026 14:33:23 +0000 Subject: [PATCH] feat: add page_configs migration Co-Authored-By: Claude Opus 4.6 --- .../a1b2c3d4e5f6_add_page_configs_table.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py diff --git a/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py b/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py new file mode 100644 index 0000000..87d78be --- /dev/null +++ b/alembic/versions/a1b2c3d4e5f6_add_page_configs_table.py @@ -0,0 +1,72 @@ +"""add page_configs table + +Revision ID: a1b2c3d4e5f6 +Revises: f6d4a1b2c3e7 +Create Date: 2026-02-10 +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy import text + +revision = 'a1b2c3d4e5f6' +down_revision = 'f6d4a1b2c3e7' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.create_table( + 'page_configs', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('post_id', sa.Integer(), nullable=False), + sa.Column('features', sa.JSON(), server_default='{}', nullable=False), + sa.Column('sumup_merchant_code', sa.String(64), nullable=True), + sa.Column('sumup_api_key', sa.Text(), nullable=True), + sa.Column('sumup_checkout_prefix', sa.String(64), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), + sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), + sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), + sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('post_id'), + ) + + # Backfill: create PageConfig for every existing page + conn = op.get_bind() + + # 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() + 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 + """)) + + # 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() + FROM posts p + WHERE p.slug = 'market' + AND p.is_page = true + AND p.deleted_at IS NULL + AND p.id NOT IN (SELECT post_id FROM page_configs) + """)) + + # 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() + FROM posts p + WHERE p.is_page = true + AND p.deleted_at IS NULL + AND p.id NOT IN (SELECT post_id FROM page_configs) + """)) + + +def downgrade() -> None: + op.drop_table('page_configs')