<aside> 🔁 Synced from GitHub #e4beb4267d8a. Edit in the paidhr-system-docs repository, not here: changes made in Notion are overwritten.

</aside>

Databases & data model

PaidHR keeps data in three kinds of SQL Server database plus MongoDB stores owned by individual services.

flowchart LR
  subgraph SQL["SQL Server"]
    M[("Membership<br/>pade_membership<br/>~150 tables")]
    T1[("Tenant DB A<br/>~550 tables + ~140 views")]
    T2[("Tenant DB B")]
    W[("Analytics<br/>reporting")]
  end
  M -- "Organisations.HostDatabaseId → HostDatabases → HostServers" --> T1 & T2
  subgraph Mongo["MongoDB"]
    ME[("EWA store<br/>earnings, withdrawals, employees")]
    MH[("Hiring store")]
    MW[("Wallet store<br/>wallets, payments, cards")]
  end

Membership: who people are and where their data lives

One shared database for the whole platform. It answers "who is this login, which organisation do they belong to, what may they do, and which tenant database holds their company?"

Area Tables
Logins AspNetUsers, UserStatus, UserPasswordHistory, UserSuspension, UserExit, UserBotSession
Roles & permissions AspNetRoles, AspNetUserRoles (system and custom roles), AspNetPermission, AspNetRolePermission
Customers Organisation (with ParentOrganisationId for subaccounts), OrganisationStatus, OrganisationType, OrganisationSetup, Plan, Agent (white-label brand: name, domain, logo)
Routing HostDatabase, HostServer
EWA bridge EwaInitialization, EwaWithdrawal, EwaConfigSetting, EwaApprover, PersonWallet
Payments bridge PaymentScheduleItemStaging, PaymentProvider, PayoutSubaccount, StatutoryPaymentFile, Invoice
Integrations Integration*, Fusion* (Oracle Fusion feeds)
Reference Bank, Country, State, Currency, TaxOffice, PensionFundAdministrator, HealthMaintenanceOrganisation, Industry
Jobs & logs BulkImportJob, ReportJob (queued reports: owner, status, result file; lives here, not in the tenant), AuditLog, ErrorLog, NotificationLog, AnnouncementLog, FeatureAnnouncementEvent (What's New engagement events, one per user, announcement, surface and day)

Organisation also carries the DataPipelineEnabled flag, set to true when a company is provisioned. FusionEmployee now also holds the personal fields the Fusion feed sends: state of origin, LGA, town, state of issuance, means of identification and its number, marital status and number of primary dependants.

Tenant: everything about a company's people

A tenant database holds one or more customer organisations. The dev tenant, for example, hosts about 40. Every table that holds customer data carries a CompanyId.

Area Main tables
People Person (with Dependents, the number of primary dependants, also on the person views), PersonStatus, PersonType, EmployeeType, Department, OfficeAddress, NextofKin, HomeAddress, EmployeeDocument, EmployeeCustomField, EmployeeLog
Pay structure Payband, Paygrade, PaygradeAllowance, Allowance, PaygradeStatutoryBenefit, PaygradeTaxRelief, PolicyGroup
Payroll Payroll, PayrollItem, PayrollItemSummary, PayrollChange, PayrollExemption, PayrollReview, PayrollSchedule, PayrollScheduleConfigSetting, CustomPayrollSchedule, PayslipDistribution, PayableType, DeductionType
Payments PaymentSchedule, PaymentScheduleItem, PaymentScheduleReview, PaymentReversal, PaymentMethod, SplitPaymentConfigSetting
Requests EmployeeRequest, EmployeeRequestReview, EmployeeRequestType, EmployeeRequestStatus
Leave LeavePolicy (now with HasLeaveAllowance / LeaveAllowanceId), LeavePolicyItem, EmployeeLeaveBalance, EmployeeLeaveBalanceLog, LeavePerk, LeavePlanningCycle, LeaveReportView, LeaveAllowanceClaim (one live claim per person, allowance and year; Allowance.IsLeaveAllowance marks a leave allowance; company settings for the payout month and proration sit on GlobalConfigSetting)
Loans & advances LoanPolicy, LoanPolicyItem, LoanRepayment, AdvancePolicy, AdvancePolicyItem, LoanGuarantor, LoanChecklistTemplateItem, LoanChecklistItem, EmployeeEosbEntry (end-of-service balance ledger: opening, adjustment, offset, payout). Interest, eligibility and guarantee rules are columns on LoanPolicy and EmployeeRequest
Exit & moves ExitPolicy, ExitPolicyItem, EmployeeExit, EmployeeSurvey, RedeploymentPolicy, EmployeeRedeployment, EmployeeSuspension
Exit cases ExitCase, ExitCaseStatus, ExitCaseLog, ExitReason, ExitHandover, ExitInterview, ExitClearanceItem, ExitClearanceTemplate / ExitClearanceTemplateItem / ExitClearanceTemplatePolicy, ExitDocument, ExitCaseDocument (company documents handed to the leaver, with waiver details) and ExitPolicyDocumentTemplate (the documents an exit policy hands out), ExitLetterTemplate, ExitSetting (now also holds the letterhead image address), and for settlements ExitSettlement, ExitSettlementComponent, ExitSettlementApproval, ExitBenefitRule (with tiers and reductions)
Reports ReportDefinition (saved Report Builder reports, with a link to the old CustomReport they were migrated from)
Absences EmployeeAbsence, EmployeeAbsenceBatch, EmployeeAbsenceReview
Time & attendance (used by ewa-service) ShiftPlans, ShiftAssignments, ShiftPeriods, TimeSheets, TimeSheetReviews, AbsentRecords (EmployeeAbsenceId links a missed shift to the EmployeeAbsence it raised for payroll review, if any — no foreign key, so HR can still delete the absence), OverTimeRequests, ShiftSwapRequests, WorkplaceConfig
Approvals ApprovalWorkflow, ApprovalWorkflowConfigSetting, ReviewEntity, AspNetRoleUser (custom roles only)
Performance ReviewCycle, CycleDuration, Objective, KeyResultItem, EmployeeObjective, CoreValue, ReviewTemplate, PerformanceFeedback and the Performance V2 tables
Requisitions Requisition, RequisitionItem, RequisitionType, RequisitionReview, RequisitionActivity
Discipline & assets EmployeeViolation*, Asset, EmployeeAsset
Comms Announcement, AnnouncementAudience, CustomNotification*
Settings GlobalConfigSetting (per company: e.g. ApprovalWorkflowsEnabled), PayrollConfigSetting, DailyJobLog

Views and computed columns

There are about 140 SQL views (View* entities), and many pages read from views rather than tables. Several important columns are computed by scalar SQL functions, for example the next approver on a request (NextReviewEntityId, NextReviewEntityRoleId) and the step counts. Another is EmployeeRequests.CummulativeAmount (what a loan or advance must repay), from fnGetCummulativeAmountFromEmployeeRequestId; since 20261201175844_DeductSalaryAdvancesInPayroll it returns the advance amount, where it would otherwise be 0, for an approved salary advance that is set to be deducted from payroll and not to be paid out by payroll. You cannot write to these columns, and changing one of their functions means dropping and re-adding the column.

Analytics

The reporting database, formerly called the Warehouse. core-backend now reads it through its own AnalyticsDbContext (connection setting AnalyticsConnection, replacing WarehouseConnection), and the migrator applies its migrations. Its first migration, AddAnalyticsViews, creates reporting views (viewPayroll, viewPayrollItemSummary, viewPerson, viewEmployeeRequest, viewContractor, viewPaymentScheduleItem and others) and stored procedures. The control-panel analytics (employee, payroll and organisation trends, payroll runs) and the CX company list read from here.

core-backend's old BI sync (people, payroll, requests, contractors, custom payments) is switched off: its calls in DataSynchronizationService are commented out under a Deprecated region. wallet-service's nightly sendWalletTransactionsToDataWarehouse is not part of this change.

MongoDB stores

Owner Holds
ewa-service (DATABASE_URL) EWA employees and employers, earnings wallets, withdrawals, invoices, settlements, fees, debit mandates, terminal devices, channel sessions
ewa-service hiring (HIRING_MONGO_URI) Jobs, applicants, interviews
wallet-service Wallets, wallet transactions, payments, payment transactions, virtual accounts, cards, bills, KYC, providers, charges, settlements
wallet-service → EWA (EWA_DATABASE_URL) A second, read connection into EWA's MongoDB

How ewa-service reaches SQL

ewa-service uses two Prisma schemas: prisma/membership/schema.prisma (33 models) and prisma/tenant/schema.prisma (49 models, mostly time & attendance, payroll schedule and request tables). TenantConnectionRegistryService resolves an organisation's HostDatabaseId to a connection the same way core-backend does, and caches one Prisma client per tenant (at most 20 at once, least recently used closed first).