Skip to content

fix: make ADK table drops conditional in all migrations, exclude test…#72

Merged
stenwire merged 1 commit into
mainfrom
root-dir-dockerfile
Jul 4, 2026
Merged

fix: make ADK table drops conditional in all migrations, exclude test…#72
stenwire merged 1 commit into
mainfrom
root-dir-dockerfile

Conversation

@stenwire

@stenwire stenwire commented Jul 4, 2026

Copy link
Copy Markdown
Owner

…s from tsconfig

Migrations dae11b7e812a and 70d75bc52042 tried to drop app_states/events/ sessions/user_states unconditionally; fresh staging DBs don't have these ADK-managed tables so all three migrations now check existence first.

Exclude the tests/ directory from Next.js tsconfig so the production Docker build doesn't fail on test-only type errors (e.g. framer-motion mock's children typed as unknown). Vitest uses its own resolution.

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • Infrastructure / CI / tooling

Checklist

  • My code follows the existing code style of this project
  • I have tested my changes locally
  • Lint passes (make lint-be / make lint-fe)
  • Tests pass (make test-be / make test-fe)
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

Screenshots / Demo

Related Issues

…s from tsconfig

Migrations dae11b7e812a and 70d75bc52042 tried to drop app_states/events/
sessions/user_states unconditionally; fresh staging DBs don't have these
ADK-managed tables so all three migrations now check existence first.

Exclude the tests/ directory from Next.js tsconfig so the production
Docker build doesn't fail on test-only type errors (e.g. framer-motion
mock's children typed as unknown). Vitest uses its own resolution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@stenwire
stenwire merged commit 46ecf47 into main Jul 4, 2026
4 checks passed
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

🤖 Hi @stenwire, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modifies two Alembic migrations to conditionally drop the 'events', 'sessions', 'user_states', and 'app_states' tables if they exist, and updates the frontend tsconfig.json to exclude the 'tests' directory. However, the reviewer raised a critical concern regarding the migrations: conditionally dropping these Google ADK-managed tables on existing databases will cause irreversible data loss of active application states and sessions. It is recommended to remove these drop statements entirely and instead configure Alembic's 'include_object' hook to ignore these tables in future autogenerated migrations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +24 to 31
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')

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')

Comment on lines +24 to 30
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))

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))

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

## 📋 Review Summary

This pull request introduces valuable fixes to the database migrations and the frontend build configuration. The changes make the database migrations more robust by conditionally dropping tables, and the tsconfig.json update correctly separates test files from the production build process.

🔍 General Feedback

  • The changes are well-implemented and follow best practices.
  • The conditional dropping of tables in migrations is a great defensive programming practice that will prevent issues in CI/CD pipelines and fresh environment setups.
  • Excluding test files from the main TypeScript configuration is a clean way to manage different build contexts.

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.

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.

Comment thread frontend/tsconfig.json
"**/*.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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

## 📋 Security Analysis Summary

This pull request, which makes ADK table drops conditional in migrations and excludes test files from tsconfig, has been reviewed for security vulnerabilities. The changes are straightforward and do not introduce any new security risks.

🔍 General Feedback

  • The changes in this pull request are well-contained and address the intended issue without introducing any side effects.
  • The code is clean, and the logic is easy to follow.
  • No security vulnerabilities were found in this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant