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
47 changes: 44 additions & 3 deletions .github/workflows/db-reset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,49 @@ on:
description: "Type 'reset-prod' to confirm"
required: true
type: string
pull_request:
paths:
- ".github/workflows/db-reset.yml"

jobs:
# Validation job - runs on PR to test connectivity (no environment = no approval needed)
validate:
name: Validate database connectivity
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
run: uv python install 3.13

- name: Sync dependencies
run: uv sync

- name: Test database connectivity
env:
SUPABASE_DB_URL: ${{ secrets.SUPABASE_POOLER_URL }}
run: |
echo "Testing database connectivity..."
uv run python -c "
from policyengine_api.config.settings import settings
from sqlmodel import create_engine, text
engine = create_engine(settings.database_url, echo=False)
with engine.connect() as conn:
result = conn.execute(text('SELECT 1'))
print('✅ Database connection successful')
"

# Reset job - only runs on manual trigger with confirmation
reset-db:
name: Reset and reseed database
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
environment: production

steps:
Expand All @@ -43,9 +81,10 @@ jobs:

- name: Reset database (init)
env:
DATABASE_URL: ${{ secrets.SUPABASE_DB_URL }}
SUPABASE_DB_URL: ${{ secrets.SUPABASE_POOLER_URL }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
LOGFIRE_TOKEN: ${{ secrets.LOGFIRE_TOKEN }}
LOGFIRE_ENVIRONMENT: prod
run: |
Expand All @@ -55,9 +94,10 @@ jobs:
- name: Seed database (lite)
if: ${{ github.event.inputs.mode == 'lite' }}
env:
DATABASE_URL: ${{ secrets.SUPABASE_DB_URL }}
SUPABASE_DB_URL: ${{ secrets.SUPABASE_POOLER_URL }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
STORAGE_BUCKET: ${{ vars.STORAGE_BUCKET }}
LOGFIRE_TOKEN: ${{ secrets.LOGFIRE_TOKEN }}
LOGFIRE_ENVIRONMENT: prod
Expand All @@ -68,9 +108,10 @@ jobs:
- name: Seed database (full)
if: ${{ github.event.inputs.mode == 'full' }}
env:
DATABASE_URL: ${{ secrets.SUPABASE_DB_URL }}
SUPABASE_DB_URL: ${{ secrets.SUPABASE_POOLER_URL }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
STORAGE_BUCKET: ${{ vars.STORAGE_BUCKET }}
LOGFIRE_TOKEN: ${{ secrets.LOGFIRE_TOKEN }}
LOGFIRE_ENVIRONMENT: prod
Expand Down
12 changes: 10 additions & 2 deletions scripts/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,21 @@ def seed_model(model_version, session, lite: bool = False) -> TaxBenefitModelVer
progress.advance(task)
continue

# Source data has dates swapped (start > end), fix ordering
# Only swap if both dates are set, otherwise keep original
if pv.start_date and pv.end_date:
start = pv.end_date # Swap: source end is our start
end = pv.start_date # Swap: source start is our end
else:
start = pv.start_date
end = pv.end_date
pv_rows.append(
{
"id": uuid4(),
"parameter_id": param_id_map[pv.parameter.id],
"value_json": json.dumps(pv.value),
"start_date": pv.start_date,
"end_date": pv.end_date,
"start_date": start,
"end_date": end,
"policy_id": None,
"dynamic_id": None,
"created_at": datetime.now(timezone.utc),
Expand Down