Skip to content

fix: isolate AANTS subscriptions by environment#1536

Merged
IsaacNguyen merged 4 commits intoicssc:mainfrom
rob-9:feat/aants-env-isolation
Apr 15, 2026
Merged

fix: isolate AANTS subscriptions by environment#1536
IsaacNguyen merged 4 commits intoicssc:mainfrom
rob-9:feat/aants-env-isolation

Conversation

@rob-9
Copy link
Copy Markdown
Contributor

@rob-9 rob-9 commented Feb 27, 2026

Summary

Addresses #1530

Staging and prod AANTS instances share the same DB. Previously, subs created on staging would be visible in prod (and vice versa) and the tRPC backend would return/modify subs across environments.

This PR makes environment a required part of each subscription so each env is isolated.

Changes

migration (0009_handy_prima.sql)

  • backfill existing rows: sets environment to 'production' where it was NULL or ''
  • make environment NOT NULL with a default of 'production'
  • expand primary key from (userId, sectionCode, year, quarter)(userId, sectionCode, year, quarter, environment)

schema (subscription.ts)

  • environment column: nullable → notNull().default('production')
  • primary key now includes environment

backend (rds.ts + notifications.ts)

  • all notification queries (retrieve, upsert, updateAll, delete, deleteAll) now filter by environment
  • getStage() helper reads process.env.STAGE, defaulting to 'production' (the old set handler was the only one that read STAGE, and it fell back to '')
  • upsert conflict target updated to include environment, and environment removed from the onConflictDoUpdate set (since it's now part of the PK)

Test plan

  • run migration against a local db with existing subs & verify NULL/empty environments backfill to 'production'
  • create a sub on staging instance & verify it doesn't appear when querying with environment = 'production'
  • upsert the same section on two different environments & verify both rows coexist (separate PK)
  • delete a subscription & verify it only deletes the row matching the current environment

Backfill NULL/empty environment values to 'production', set NOT NULL
with default, and include environment in the composite primary key so
subscriptions from different deployment stages don't collide.
Add environment parameter to all RDS notification methods and filter
queries by it. Resolve STAGE env var in every tRPC handler (defaulting
to 'production') so each deployment only sees its own subscriptions.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

@alexespejo alexespejo requested a review from IsaacNguyen March 11, 2026 20:15
IsaacNguyen
IsaacNguyen previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Contributor

@IsaacNguyen IsaacNguyen left a comment

Choose a reason for hiding this comment

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

So sorry for taking so long to get around to this, but great job on the PR! Everything looks good to me!

I'm not sure I'm the biggest fan of defaulting the stage to "production", but we kind of have to in this situation (I would've done the same).

I think we should hold off from merging this one until after Spring enrollment is completely done (maybe after Week 2).

@IsaacNguyen
Copy link
Copy Markdown
Contributor

Hello! Sorry for the delay in getting this merged (there are some merge conflicts now). But once you squash these conflicts, we'll get this merged in!

@rob-9
Copy link
Copy Markdown
Contributor Author

rob-9 commented Apr 14, 2026

migration looks clean

@rob-9 rob-9 requested a review from IsaacNguyen April 14, 2026 17:25
Copy link
Copy Markdown
Contributor

@IsaacNguyen IsaacNguyen left a comment

Choose a reason for hiding this comment

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

LGTM!

@IsaacNguyen IsaacNguyen merged commit da6079d into icssc:main Apr 15, 2026
1 check passed
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.

2 participants