Skip to content

Finance Table Cleanup

Related documentation: Finance Module Backend · Data ownership · Core Backend · Auth Backend

This document defines which legacy tables must be removed from the Finance database once the platform migration is complete.

This page is not about what Finance historically had.

It is about:

  • what now belongs to Core
  • what now belongs to Auth
  • what Finance still keeps temporarily for runtime compatibility
  • what can be deleted from Finance immediately after migration
  • what must be deleted later, only after Finance code stops using it

These tables belong to Platform Core:

  • Company
  • BusinessUnit

Reason:

  • company master data is platform organizational data
  • business unit master data is platform organizational data
  • neither table is finance-domain business data

Finance may reference company ids and business unit ids, but Finance should not be the long-term source of truth for those entities.

These tables belong to Platform Auth:

  • User
  • Account
  • Session
  • VerificationToken
  • CompanyMembership
  • BusinessUnitMembership

Reason:

  • identity belongs to Auth
  • memberships belong to Auth
  • access/session state belongs to Auth
  • Finance must consume user/access context, not own it

Finance should keep only finance-domain tables such as:

  • Invoice
  • Payment
  • ApprovalPolicy
  • ApprovalStep
  • ApprovalAction
  • Vendor
  • VendorCompanyLink
  • Customer
  • CustomerCompanyLink
  • ExpenseCategory
  • Income
  • IncomePayment
  • XeroConnection
  • XeroSyncLog
  • AuditLog

This list is illustrative, not exhaustive. The rule is:

if the table represents finance workflow or finance reporting data, it stays in Finance
if the table represents platform organization, identity, membership, or session data, it does not belong in Finance

The current canonical Finance schema is:

The old legacy schema that still shows previously-owned identity and membership tables is:

Important current fact:

  • the current canonical Finance schema no longer contains User, Account, Session, VerificationToken, CompanyMembership, or BusinessUnitMembership
  • but the current Finance schema still contains Company and BusinessUnit

That means the cleanup has two phases:

  1. remove legacy identity/access tables that are already no longer modeled in Finance
  2. remove Company and BusinessUnit only after Finance is fully refactored to read Core-owned company/business-unit master data

These tables are no longer part of the canonical Finance schema and should be treated as legacy leftovers if they still exist in the Finance database.

They should be dropped after final verification that no raw SQL, views, triggers, ad-hoc scripts, or external jobs still depend on them.

  • User
  • Account
  • Session
  • VerificationToken

Why they must be removed:

  • identity is now owned by Auth
  • session lifecycle is now owned by Auth
  • Finance should not persist platform users or auth sessions
  • CompanyMembership
  • BusinessUnitMembership

Why they must be removed:

  • company memberships are now owned by Auth
  • business unit memberships are now owned by Auth
  • Finance must rely on Auth-provided access context and ids, not local membership rows

These tables are:

  • not part of the current canonical Finance schema
  • safe cleanup targets
  • remove now after verification

These tables do not belong to Finance architecturally, but they are still used by the current Finance runtime and therefore cannot be dropped yet.

  • Company
  • BusinessUnit

Why they are not removable yet:

  • current Finance code still queries prisma.company
  • current Finance code still queries prisma.businessUnit
  • current Finance admin, upload, stats, Kisum-link, and invoice/income flows still depend on those tables

Examples in current Finance code:

Company and BusinessUnit may be removed from Finance only after:

  • Finance no longer reads or writes those tables locally
  • Finance resolves company/business-unit master data from Core
  • all Finance routes and services that currently use Prisma company/BU reads have been migrated
  • background jobs, import scripts, and reporting queries have been updated

These tables are:

  • architecturally misplaced in Finance
  • still operationally required today
  • remove later after code migration

5. Enums and related objects that must not be dropped blindly

Section titled “5. Enums and related objects that must not be dropped blindly”

Even when legacy tables are removed, some enums may still be used by Finance workflow tables.

Important examples in the current Finance schema:

  • CompanyRole
  • BusinessUnitRole

These are still used by approval workflow tables, especially:

So the cleanup rule is:

do not drop enums just because a legacy table disappeared
drop an enum only after confirming no remaining table, column, constraint, or function still references it

TableTarget ownerFinance status todayCleanup action
UserAuthlegacy onlyremove now
AccountAuthlegacy onlyremove now
SessionAuthlegacy onlyremove now
VerificationTokenAuthlegacy onlyremove now
CompanyMembershipAuthlegacy onlyremove now
BusinessUnitMembershipAuthlegacy onlyremove now
CompanyCorestill used by Finance runtimeremove later
BusinessUnitCorestill used by Finance runtimeremove later

Before dropping any table from Finance, verify:

  • no Prisma model still references it in the canonical schema
  • no raw SQL migration, script, cron, or report still queries it
  • no route handler still depends on it
  • no foreign key from a retained finance-domain table still points to it
  • no enum or function used by active finance tables is being dropped indirectly

For Company and BusinessUnit, deletion is blocked until Finance has completed the Core master-data migration.


The Finance cleanup should follow this order:

  1. remove legacy Auth-owned tables from Finance
  2. keep Company and BusinessUnit temporarily while Finance still uses them
  3. migrate Finance runtime reads/writes to Core-owned master data
  4. then remove Company and BusinessUnit from Finance

This is the only safe cleanup sequence.