Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions backend/alembic/versions/70d75bc52042_transactions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('events')
op.drop_table('sessions')
op.drop_table('user_states')
op.drop_table('app_states')
conn = op.get_bind()
existing = sa.inspect(conn).get_table_names()
for tbl in ('events', 'sessions', 'user_states', 'app_states'):
if tbl in existing:
op.drop_table(tbl)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 This is a great improvement for making the migrations more robust. Checking if the tables exist before dropping them prevents errors when running migrations on a fresh database where these tables might not have been created by the ADK.

with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('transaction_metadata', sa.JSON(), nullable=True))
batch_op.drop_column('metadata')
Comment on lines +24 to 31

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

⚠️ Critical Data Loss Risk

These tables (events, sessions, user_states, app_states) are managed by the Google ADK library and contain active application state and session data.

While making the drops conditional prevents the migration from crashing on a fresh database (where the tables do not exist), it introduces a severe bug on existing databases (such as local development or production):

  1. On any database where these tables exist, tbl in existing will evaluate to True.
  2. The migration will proceed to drop them, resulting in complete and irreversible data loss of all ADK-managed sessions and states.

Solution

  1. Remove the drop statements entirely from this migration.
  2. To prevent Alembic from autogenerating these drop statements in future migrations, configure the include_object hook in backend/alembic/env.py to ignore these tables:
def include_object(object, name, type_, reflected, compare_to):
    if type_ == "table" and name in {"events", "sessions", "user_states", "app_states"}:
        return False
    return True
Suggested change
conn = op.get_bind()
existing = sa.inspect(conn).get_table_names()
for tbl in ('events', 'sessions', 'user_states', 'app_states'):
if tbl in existing:
op.drop_table(tbl)
with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('transaction_metadata', sa.JSON(), nullable=True))
batch_op.drop_column('metadata')
with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('transaction_metadata', sa.JSON(), nullable=True))
batch_op.drop_column('metadata')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_states')
op.drop_table('app_states')
op.drop_table('events')
op.drop_table('sessions')
conn = op.get_bind()
existing = sa.inspect(conn).get_table_names()
for tbl in ('user_states', 'app_states', 'events', 'sessions'):
if tbl in existing:
op.drop_table(tbl)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Good catch! This change correctly makes the migration idempotent and safer to run in different database states.

with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('raw_webhook_payload', sa.JSON(), nullable=True))
Comment on lines +24 to 30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

⚠️ Critical Data Loss Risk

These tables (events, sessions, user_states, app_states) are managed by the Google ADK library and contain active application state and session data.

While making the drops conditional prevents the migration from crashing on a fresh database (where the tables do not exist), it introduces a severe bug on existing databases (such as local development or production):

  1. On any database where these tables exist, tbl in existing will evaluate to True.
  2. The migration will proceed to drop them, resulting in complete and irreversible data loss of all ADK-managed sessions and states.

Solution

  1. Remove the drop statements entirely from this migration.
  2. To prevent Alembic from autogenerating these drop statements in future migrations, configure the include_object hook in backend/alembic/env.py to ignore these tables:
def include_object(object, name, type_, reflected, compare_to):
    if type_ == "table" and name in {"events", "sessions", "user_states", "app_states"}:
        return False
    return True
Suggested change
conn = op.get_bind()
existing = sa.inspect(conn).get_table_names()
for tbl in ('user_states', 'app_states', 'events', 'sessions'):
if tbl in existing:
op.drop_table(tbl)
with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('raw_webhook_payload', sa.JSON(), nullable=True))
with op.batch_alter_table('payment_transactions', schema=None) as batch_op:
batch_op.add_column(sa.Column('raw_webhook_payload', sa.JSON(), nullable=True))


Expand Down
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
"exclude": ["node_modules", "tests"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Excluding the `tests` directory from the main `tsconfig.json` is a good practice. This ensures that test-specific configurations and types do not interfere with the production build, which was the goal of this PR.

}
Loading