Skip to content

Write to the Associations app on confirming Auto-Associations - #152

Open
rmartinsen-ucd wants to merge 4 commits into
mainfrom
rpm/write-to-associations-app
Open

rmartinsen-ucd wants to merge 4 commits into
mainfrom
rpm/write-to-associations-app

Conversation

@rmartinsen-ucd

@rmartinsen-ucd rmartinsen-ucd commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #78

What this does

Confirming the Auto-Associations stage now writes the cycle's data to the Associations app database, so manual associations can be made in AD419 Next. The Manual Associations stage unlocks only if the write succeeds.

  • The write loads rows into Load_ tables in the target database, then runs one batch on the target server. That batch, in a single transaction, sets CurrentFiscalYear, clears and refills OrgR_x_FinancialDepartment, Project, ProjXOrgR, AllAE_Expenses and Associations, checks row counts, totals and flags, and commits. Any failure rolls back, leaves the stage unconfirmed and shows the message on the stage.
  • The target is reached through a linked server on the datamart. Every statement is handed over with EXEC (...) AT [linked server], so it needs RPC Out but not MSDTC. The transaction lives inside the remote batch.
  • The load sends rows as INSERT ... VALUES statements of up to 1000 rows each, which run whole on the target. A four part name insert through the linked server would go row by row, so it is not used.
  • The load can be abandoned, since it only fills the load tables. From the swap on, the write runs to its end and is recorded even if the request is dropped.
  • The Manual Associations stage links to AD419 Next, shows the last write, and has a "Reset to auto-associations" button that reruns the same write.
  • A write asks before discarding manual associations when any of these holds: it is a reset, this app has a successful write on record for the cycle, or the target's CurrentFiscalYear already equals this cycle's year. The last one means an environment with no record of its own (test, a local build, a restored app database) cannot wipe this cycle's work unasked.
  • Each write is recorded in app.AssociationsAppWrites (two EF migrations). The record holds the totals as read from staging next to the totals written, so rounding to the target's column scales is visible.
  • Five new views in the data DACPAC shape the rows with the target's column names. Projects under $100 are left out, and the writer checks that again before loading.
  • Values are fitted to the target's real column definitions, read at write time: free text is truncated, codes and ids must fit or the write fails, amounts are rounded to the target's scale.
  • The app takes no backup. That is done by hand before the first write.

Before a real write

  1. Back up the target tables by hand.
  2. Enable RPC Out on the linked server and map the app's login, with rights to create and drop tables in the target database.
  3. Run the three checks in database/donbot/associations-app-setup.sql (triggers, transaction probe, load timing).
  4. Set the GitHub Environment variables ASSOCIATIONS_APP_LINKED_SERVER and ASSOCIATIONS_APP_DATABASE. There is no default, so an environment with nothing set fails the write with a clear message. Only prod should name ad419.

For local development, npm run db:associations-app creates a stand-in AssociationsAppDev database in the SQL container.

Things to know

  • isNonEmpExp, Sub_Exp_SFN and Staff_Grp_Cd on AllAE_Expenses are written as NULL. AD419 Next is not believed to read them. Worth a look at what last year's load put there before the first production write.
  • The swap's checks compare the live tables against the rows that were loaded. They prove the copy, not the views that produced the rows; those are covered by their own tests.
  • Main's "Rebuild auto-associations" button is still available after this stage is complete. A rebuild at that point leaves the Associations app out of date until someone uses "Reset to auto-associations".
  • An AE project shared by an under $100 project and a normal one has its unassociated expenses marked not associable. That is the literal reading of the issue and may want narrowing.
  • A direct API call that completes this stage when it is already complete reruns the write. The discard rule still applies.
  • The one at a time lock is per app instance.
  • Float totals on Associations are compared within a small tolerance.

Testing

826 server tests and 278 client tests pass. Client lint, type check and build are clean.

The store's tests run twice: directly, and through a linked server that points back at the test container, so the EXEC ... AT path is covered, including check failures coming back with their message. Not verified: the real linked server to donbot (login mapping, RPC Out, speed over the network) and a browser click-through.

🤖 Generated with Claude Code

rmartinsen-ucd and others added 2 commits November 30, 2026 07:55
Confirming stage 7 loads the cycle's projects, expenses and associations
into load tables in the Associations app database, then swaps them into
the live tables in one transaction that also sets CurrentFiscalYear and
checks counts, totals and flags. Stage 8 unlocks only if the write
succeeds, and gets a Reset to auto-associations button that reruns it.

Closes #78

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ions-app

# Conflicts:
#	client/src/components/autoAssociations/AutoAssociationsStage.tsx
#	client/src/test/mswUtils.ts
#	client/src/test/routes/(authenticated)/autoAssociations.test.tsx
#	server/Program.cs
#	server/Workflow/WorkflowService.cs
#	tests/server.tests/Import/ImportRunsControllerTests.cs
#	tests/server.tests/OrgR/OrgRControllerTests.cs
#	tests/server.tests/ProjectIdentification/ProjectIdentificationServiceTests.cs
#	tests/server.tests/ProjectList/ProjectListControllerTests.cs
#	tests/server.tests/Workflow/WorkflowControllerTests.cs
#	tests/server.tests/Workflow/WorkflowServiceTests.cs
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7d64b37f-36ca-4950-a733-ed615944c217
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Ask before discarding when the target is already on this cycle's year,
even with no write on record here. Load rows as VALUES statements that
run whole on the target, not a four part insert that goes row by row.
Run the swap to its end once the load is done. Record source totals
next to the written ones. Run the store tests through a loopback linked
server as well as directly.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Comment on lines 124 to 130
<button
className="btn btn-sm"
disabled={rebuilding || continueMutation.isPending}
onClick={() => setConfirmingRebuild(true)}
type="button"
>
{rebuilding ? 'Rebuilding...' : 'Rebuild auto-associations'}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Require reopening before rebuilding exported expenses

One user can confirm stage 7, start manual associations, then revisit stage 7 and click Rebuild. Even with identical inputs, the rebuild gives every local expense a new ID while AD419 Next keeps the old IDs. Disable Rebuild on a completed stage and enforce the same check in the endpoint. The existing reopen and confirm flow can handle an intentional rebuild.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can depend on the user to orchestrate between ad419 and the associations app. It's expected that if you rebuild associations, you'll push them to the app. This will become obsolete when we bring the associations app into ad419

Comment thread server/Workflow/WorkflowService.cs Resolved
An included expense can sit on an AE project that is not on the cycle's
NIFA project list, or is listed with no PI. The Associations app expenses
view now falls back to PGMProjects by AE project number, so the PI name
departments group by is not blank.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Write to Associations App (CAES-DONBOT)

2 participants