Skip to main content

Operion Database Documentation

Opsnexa Database Documentation​

Databaseopsnexa (PostgreSQL 18, schema public)
Tables34 (33 business tables + 1 EF Core migration table)
Extensionspgcrypto
Stored routines2 functions, 2 procedures (one procedure has two overloads)
Sourcepg_dump taken 2026-10-02

1. Overview​

Opsnexa is a multi-tenant business-operations application. Each tenant is an organization; users, employees, customers, services, income, expenses, accounts and payments all belong to one organization. Behaviour that varies per business (dropdown values, roles, departments and so on) is driven by reference tables that mix system-defined rows (shared by every organization) with organization-defined rows.

The database has seven functional areas:

S.NoModuleTables
1Tenancy, Users & Accessorganizations, users, user_security, user_sessions, user_preferences, roles, user_roles, permissions, role_permissions, organization_invitations, pending_signups
2Master & Reference Datamaster_categories, master_values, departments, designations, work_locations
3HRemployees, employee_photos, employee_documents, attendance, wages
4Customers, Services & Incomecustomers, services, income
5ExpensesExpenseCategories, ExpensePayees, Expense
6Accounts & Paymentsorganizationaccount, bankaccountdetails, debitcarddetails, creditcarddetails, walletdetails, payment
7System__EFMigrationsHistory

2. Design Conventions​

  • Multi-tenancy. Business tables carry organization_id (uuid). Many also store a denormalized org_code; where a composite foreign key (organization_id, org_code) → organizations(id, code) exists, it guarantees the two always match (used on customers, employees, designations, services, master_categories).
  • System vs. organization rows. departments, designations, roles, master_categories, master_values and work_locations hold shared rows (is_system_defined = true, organization_id NULL) and organization rows. On departments and designations, check constraints enforce this scoping, and partial unique indexes keep codes and names unique within each scope.
  • Lookup values. Dropdown-style columns (gender, currency, payment mode, tax and so on) are stored as *_id foreign keys to master_values. Each master_values row belongs to a master_categories row. Section 6 lists which category each column uses.
  • Soft delete. Tables use deleted_at (timestamp) or is_deleted (boolean) instead of removing rows. Unique indexes are usually partial (WHERE deleted_at IS NULL) so deleted rows do not block re-use of codes or emails.
  • Audit columns. Most tables have created_at, updated_at, created_by, updated_by. The *_by columns hold a users.id (bigint); only some tables enforce this with a foreign key (see Section 9).
  • Status columns. Status values are restricted by CHECK constraints (Section 7).
  • Encrypted data. Account-detail tables store sensitive values in *encrypted columns, with a matching *hash column for lookups. Card numbers are stored as a token plus a hash and the last four digits only.
  • Identifiers. Core business tables use uuid primary keys (gen_random_uuid()). Reference and security tables (users, roles, departments, master_*, user_sessions and so on) use bigint keys generated from sequences.
  • Naming. The EF-created expense tables use PascalCase (Expense, ExpenseCategories, ExpensePayees). The account/payment tables use lowercase without underscores (organizationaccount, payment). All other tables use snake_case.
  • Binary files. Employee photos and documents are stored in the database as bytea.

3. Entity-Relationship Diagrams​

The diagrams are written in Mermaid. Foreign keys to users that only record who created/updated/deleted a row are left out to keep the diagrams readable, and foreign keys to master_values are drawn as one line per table, labelled with the number of lookup columns (e.g. lookups(6)). Section 5 lists every column.

Legend: ||--o{ one-to-many, ||--o| one-to-one, |o--o{ optional parent. PK primary key, FK foreign key, UK unique column. Tables drawn with only a primary key belong to another module and are shown for context.

Overview (all tables, relationships only)​

erDiagram
organizations |o--o{ ExpenseCategories : "OrganizationId"
organizations ||--o{ ExpensePayees : "OrganizationId"
organizationaccount |o--o{ Expense : "AccountId"
ExpenseCategories ||--o{ Expense : "CategoryId"
organizations ||--o{ Expense : "OrganizationId"
ExpensePayees ||--o{ Expense : "VendorPayeeId"
employees ||--o{ attendance : "employee_id"
organizations ||--o{ attendance : "organization_id"
organizations ||--o{ customers : "organization_id"
organizations |o--o{ designations : "organization_id"
employees ||--o{ employee_documents : "employee_id"
employees ||--o| employee_photos : "employee_id"
departments |o--o{ employees : "department_id"
designations ||--o{ employees : "designation_id"
organizations ||--o{ employees : "organization_id"
employees |o--o{ employees : "reporting_manager_id"
work_locations |o--o{ employees : "work_location_id"
organizationaccount |o--o{ income : "account_id"
customers ||--o{ income : "customer_id"
organizations ||--o{ income : "organization_id"
services |o--o{ income : "service_id"
users ||--o{ organization_invitations : "invited_by"
organizations ||--o{ organization_invitations : "organization_id"
roles |o--o{ organization_invitations : "role_id"
organizations |o--o{ master_categories : "organization_id"
master_categories ||--o{ master_values : "master_category_id"
organization_invitations |o--o{ pending_signups : "invitation_id"
organizations |o--o{ pending_signups : "organization_id"
roles |o--o{ pending_signups : "role_id"
permissions ||--o{ role_permissions : "permission_id"
roles ||--o{ role_permissions : "role_id"
organizations |o--o{ roles : "organization_id"
organizations ||--o{ services : "organization_id"
organizations ||--o{ user_preferences : "organization_id"
users ||--o| user_preferences : "user_id"
roles ||--o{ user_roles : "role_id"
users ||--o{ user_roles : "user_id"
users ||--o| user_security : "user_id"
users ||--o{ user_sessions : "user_id"
organizations ||--o{ users : "organization_id"
organizationaccount ||--o| bankaccountdetails : "organizationaccountid"
organizationaccount ||--o| creditcarddetails : "organizationaccountid"
organizationaccount ||--o| debitcarddetails : "organizationaccountid"
organizations ||--o{ organizationaccount : "organizationid"
organizations ||--o{ payment : "organizationid"
organizationaccount ||--o| walletdetails : "organizationaccountid"
master_values ||--o{ Expense : "lookups(3)"
master_values ||--o{ customers : "lookups(5)"
master_values ||--o{ employees : "lookups(6)"
master_values ||--o{ income : "lookups(4)"
master_values ||--o{ services : "lookups(7)"

1. Tenancy, Users & Access​

erDiagram
Expense {
uuid Id PK
}
ExpenseCategories {
uuid Id PK
}
ExpensePayees {
uuid Id PK
}
attendance {
uuid id PK
}
customers {
uuid id PK
}
designations {
bigint id PK
}
employees {
uuid id PK
}
income {
uuid id PK
}
master_categories {
bigint id PK
}
organization_invitations {
uuid id PK
uuid organization_id FK
bigint invited_by FK
varchar token_hash UK
bigint role_id FK
}
organizationaccount {
uuid id PK
}
organizations {
uuid id PK
varchar code UK
}
payment {
uuid id PK
}
pending_signups {
uuid id PK
uuid invitation_id FK
uuid organization_id FK
bigint role_id FK
}
permissions {
bigint id PK
varchar name UK
}
role_permissions {
bigint role_id PK,FK
bigint permission_id PK,FK
}
roles {
bigint id PK
uuid organization_id FK
}
services {
uuid id PK
}
user_preferences {
uuid id PK
bigint user_id FK,UK
uuid organization_id FK
}
user_roles {
bigint id PK
bigint user_id FK
bigint role_id FK
}
user_security {
bigint user_id PK,FK
}
user_sessions {
bigint id PK
bigint user_id FK
varchar refresh_token_hash UK
}
users {
bigint id PK
uuid organization_id FK
}
organizations |o--o{ ExpenseCategories : "OrganizationId"
organizations ||--o{ ExpensePayees : "OrganizationId"
organizations ||--o{ Expense : "OrganizationId"
organizations ||--o{ attendance : "organization_id"
organizations ||--o{ customers : "organization_id"
organizations |o--o{ designations : "organization_id"
organizations ||--o{ employees : "organization_id"
organizations ||--o{ income : "organization_id"
users ||--o{ organization_invitations : "invited_by"
organizations ||--o{ organization_invitations : "organization_id"
roles |o--o{ organization_invitations : "role_id"
organizations |o--o{ master_categories : "organization_id"
organization_invitations |o--o{ pending_signups : "invitation_id"
organizations |o--o{ pending_signups : "organization_id"
roles |o--o{ pending_signups : "role_id"
permissions ||--o{ role_permissions : "permission_id"
roles ||--o{ role_permissions : "role_id"
organizations |o--o{ roles : "organization_id"
organizations ||--o{ services : "organization_id"
organizations ||--o{ user_preferences : "organization_id"
users ||--o| user_preferences : "user_id"
roles ||--o{ user_roles : "role_id"
users ||--o{ user_roles : "user_id"
users ||--o| user_security : "user_id"
users ||--o{ user_sessions : "user_id"
organizations ||--o{ users : "organization_id"
organizations ||--o{ organizationaccount : "organizationid"
organizations ||--o{ payment : "organizationid"

2. Master & Reference Data​

erDiagram
departments {
bigint id PK
}
designations {
bigint id PK
uuid organization_id FK
varchar org_code FK
}
employees {
uuid id PK
}
master_categories {
bigint id PK
uuid organization_id FK
varchar org_code FK
}
master_values {
bigint id PK
bigint master_category_id FK
}
organizations {
uuid id PK
}
work_locations {
bigint id PK
}
organizations |o--o{ designations : "organization_id"
departments |o--o{ employees : "department_id"
designations ||--o{ employees : "designation_id"
work_locations |o--o{ employees : "work_location_id"
organizations |o--o{ master_categories : "organization_id"
master_categories ||--o{ master_values : "master_category_id"

3. HR​

erDiagram
attendance {
uuid id PK
uuid organization_id FK
uuid employee_id FK
}
departments {
bigint id PK
}
designations {
bigint id PK
}
employee_documents {
uuid id PK
uuid employee_id FK
}
employee_photos {
uuid employee_id PK,FK
}
employees {
uuid id PK
uuid organization_id FK
varchar org_code FK
bigint gender_id FK
bigint marital_status_id FK
bigint blood_group_id FK
bigint department_id FK
bigint designation_id FK
bigint employment_type_id FK
uuid reporting_manager_id FK
bigint work_location_id FK
bigint pay_type_id FK
bigint shift_type_id FK
}
master_values {
bigint id PK
}
organizations {
uuid id PK
}
wages {
uuid id PK
}
work_locations {
bigint id PK
}
employees ||--o{ attendance : "employee_id"
organizations ||--o{ attendance : "organization_id"
employees ||--o{ employee_documents : "employee_id"
employees ||--o| employee_photos : "employee_id"
departments |o--o{ employees : "department_id"
designations ||--o{ employees : "designation_id"
organizations ||--o{ employees : "organization_id"
employees |o--o{ employees : "reporting_manager_id"
work_locations |o--o{ employees : "work_location_id"
master_values ||--o{ employees : "lookups(6)"

4. Customers, Services & Income​

erDiagram
customers {
uuid id PK
uuid organization_id FK
varchar org_code FK
bigint customer_type_id FK
bigint industry_id FK
bigint customer_group_id FK
bigint payment_terms_id FK
bigint payment_method_id FK
}
income {
uuid id PK
uuid organization_id FK
uuid customer_id FK
uuid service_id FK
bigint category_id FK
bigint currency_id FK
bigint payment_mode_id FK
uuid account_id FK
bigint payment_status_id FK
}
master_values {
bigint id PK
}
organizationaccount {
uuid id PK
}
organizations {
uuid id PK
}
services {
uuid id PK
uuid organization_id FK
varchar org_code FK
bigint category_id FK
bigint sub_category_id FK
bigint pricing_type_id FK
bigint unit_of_measurement_id FK
bigint tax_id FK
bigint applicable_for_id FK
bigint discount_type_id FK
}
organizations ||--o{ customers : "organization_id"
organizationaccount |o--o{ income : "account_id"
customers ||--o{ income : "customer_id"
organizations ||--o{ income : "organization_id"
services |o--o{ income : "service_id"
organizations ||--o{ services : "organization_id"
master_values ||--o{ customers : "lookups(5)"
master_values ||--o{ income : "lookups(4)"
master_values ||--o{ services : "lookups(7)"

5. Expenses​

erDiagram
Expense {
uuid Id PK
uuid OrganizationId FK
uuid CategoryId FK
uuid VendorPayeeId FK
bigint CurrencyId FK
bigint PaymentModeId FK
uuid AccountId FK
bigint PaymentStatusId FK
}
ExpenseCategories {
uuid Id PK
uuid OrganizationId FK
}
ExpensePayees {
uuid Id PK
uuid OrganizationId FK
}
master_values {
bigint id PK
}
organizationaccount {
uuid id PK
}
organizations {
uuid id PK
}
organizations |o--o{ ExpenseCategories : "OrganizationId"
organizations ||--o{ ExpensePayees : "OrganizationId"
organizationaccount |o--o{ Expense : "AccountId"
ExpenseCategories ||--o{ Expense : "CategoryId"
organizations ||--o{ Expense : "OrganizationId"
ExpensePayees ||--o{ Expense : "VendorPayeeId"
master_values ||--o{ Expense : "lookups(3)"

6. Accounts & Payments​

erDiagram
Expense {
uuid Id PK
}
bankaccountdetails {
uuid id PK
uuid organizationaccountid FK,UK
}
creditcarddetails {
uuid id PK
uuid organizationaccountid FK,UK
}
debitcarddetails {
uuid id PK
uuid organizationaccountid FK,UK
}
income {
uuid id PK
}
organizationaccount {
uuid id PK
uuid organizationid FK
}
organizations {
uuid id PK
}
payment {
uuid id PK
uuid organizationid FK
}
walletdetails {
uuid id PK
uuid organizationaccountid FK,UK
}
organizationaccount |o--o{ Expense : "AccountId"
organizationaccount |o--o{ income : "account_id"
organizationaccount ||--o| bankaccountdetails : "organizationaccountid"
organizationaccount ||--o| creditcarddetails : "organizationaccountid"
organizationaccount ||--o| debitcarddetails : "organizationaccountid"
organizations ||--o{ organizationaccount : "organizationid"
organizations ||--o{ payment : "organizationid"
organizationaccount ||--o| walletdetails : "organizationaccountid"

An interactive version of all diagrams is in opsnexa_er_diagrams.html.

4. Table Index​

TableModulePurpose
organizationsTenancy, Users & AccessThe tenant (company). Holds identity, contact/address, GSTIN/PAN, base currency, fiscal-year start, time zone and invoice prefix. code is unique and is copied into org_code on many child tables.
usersTenancy, Users & AccessApplication login accounts. Each user belongs to one organization; email is unique among non-deleted users.
user_securityTenancy, Users & AccessOne-to-one security state for a user: failed-login lockout, password expiry/reset, and email-verification tokens (hashed).
user_sessionsTenancy, Users & AccessRefresh-token sessions per user/device, with expiry, last activity and revocation time.
user_preferencesTenancy, Users & AccessPer-user UI preferences (currently page size) scoped by organization and preference type.
rolesTenancy, Users & AccessRoles used for access control. System roles (organization NULL) are shared by all tenants; organizations may define their own.
user_rolesTenancy, Users & AccessAssigns roles to users, with assigner and optional expiry.
permissionsTenancy, Users & AccessCatalog of named permissions.
role_permissionsTenancy, Users & AccessMany-to-many mapping between roles and permissions.
organization_invitationsTenancy, Users & AccessEmail invitations to join an organization, with hashed token, role to assign, expiry and accepted/revoked timestamps.
pending_signupsTenancy, Users & AccessStaging table for self-signup and invited signup until the email OTP is verified. Holds the OTP hash and attempt counter.
master_categoriesMaster & Reference DataGroups of dropdown/lookup values (e.g. GENDER, PAYMENT_MODE, CURRENCY). System-defined or organization-defined.
master_valuesMaster & Reference DataThe individual lookup values belonging to a master category. Referenced by many business tables through *_id columns.
departmentsMaster & Reference DataHR departments. System-defined (shared) or organization-specific.
designationsMaster & Reference DataJob titles/designations. System-defined (shared) or organization-specific.
work_locationsMaster & Reference DataWork sites/offices used by employees and wages.
employeesHREmployee master record: personal, contact, job, pay and emergency details. Supports a reporting-manager hierarchy through a self-reference.
employee_photosHREmployee photo stored as binary data (one per employee).
employee_documentsHRUploaded employee documents stored as binary data (one per document type per employee).
attendanceHRDaily attendance per employee (status, in/out time, break minutes). One active row per employee per day.
wagesHRWage/payroll records per employee and pay period: base wage, overtime, allowances, deductions, net payable, and payment details.
customersCustomers, Services & IncomeCustomer master: contact details, billing/service addresses, GSTIN/PAN, payment terms and credit limit.
servicesCustomers, Services & IncomeService catalog: pricing type, unit, default rate, cost, minimum charge, tax and discount rules.
incomeCustomers, Services & IncomeIncome (sales/invoice) records for customers, with tax breakup, payment status/mode and optional service and account.
ExpenseCategoriesExpensesExpense categories, system-defined or organization-defined.
ExpensePayeesExpensesVendors/payees that expenses are paid to.
ExpenseExpensesExpense records with tax breakup, payment status/mode, due/payment dates and reimbursable/deductible/recurring flags.
organizationaccountAccounts & PaymentsParent record for every money account of an organization. accounttype (BANK, DEBIT_CARD, CREDIT_CARD, WALLET) decides which detail table holds its data.
bankaccountdetailsAccounts & PaymentsBank account details for an account of type BANK. Sensitive fields are stored encrypted with searchable hashes.
debitcarddetailsAccounts & PaymentsDebit card details for an account of type DEBIT_CARD (token, hash, last four digits, expiry, network).
creditcarddetailsAccounts & PaymentsCredit card details for an account of type CREDIT_CARD, including encrypted limits.
walletdetailsAccounts & PaymentsWallet details for an account of type WALLET. Sensitive fields are stored encrypted.
paymentAccounts & PaymentsPayment ledger entries (received/paid) with party, reference, amount, mode and optional attachment.
__EFMigrationsHistorySystemEntity Framework Core migration tracking table. Managed by the framework; not a business table.

5. Data Dictionary​

1. Tenancy, Users & Access​

organizations​

The tenant (company). Holds identity, contact/address, GSTIN/PAN, base currency, fiscal-year start, time zone and invoice prefix. code is unique and is copied into org_code on many child tables.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK; UNIQUE with code
namevarchar(200)NO
codevarchar(50)NOUNIQUE; UNIQUE with id
descriptiontextYES
emailvarchar(255)YES
phonevarchar(30)YES
websitevarchar(255)YES
address_line1varchar(255)YES
address_line2varchar(255)YES
cityvarchar(100)YES
statevarchar(100)YES
countryvarchar(100)YES
postal_codevarchar(20)YES
logo_urltextYES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, SUSPENDED
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYESFK → users.id (ON DELETE SET NULL)
updated_bybigintYESFK → users.id (ON DELETE SET NULL)
deleted_attimestamptzYES
gstinvarchar(20)YES
panvarchar(20)YES
tax_registration_typevarchar(50)YES
base_currencyvarchar(50)YES
fiscal_year_startvarchar(20)YES
time_zonevarchar(50)YES
invoice_prefixvarchar(20)YES

Table constraints

  • UNIQUE (id, code)

Referenced by: ExpenseCategories (OrganizationId), ExpensePayees (OrganizationId), Expense (OrganizationId), attendance (organization_id), customers (organization_id), designations (organization_id), employees (organization_id), income (organization_id), organization_invitations (organization_id), master_categories (organization_id), pending_signups (organization_id), roles (organization_id), services (organization_id), user_preferences (organization_id), users (organization_id), organizationaccount (organizationid), payment (organizationid)

users​

Application login accounts. Each user belongs to one organization; email is unique among non-deleted users.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidNOFK → organizations.id (ON DELETE RESTRICT)
full_namevarchar(200)NO
emailvarchar(255)NO
password_hashvarchar(255)NO
display_namevarchar(200)YES
phone_numbervarchar(30)YES
profile_image_urltextYES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, PENDING, SUSPENDED
email_verifiedbooleanNOfalse
phone_number_verifiedbooleanNOfalse
last_login_attimestamptzYES
password_changed_attimestamptzYES
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYESFK → users.id (ON DELETE SET NULL)
updated_bybigintYESFK → users.id (ON DELETE SET NULL)
deleted_attimestamptzYES
org_codevarchar(50)NO

Referenced by: organization_invitations (invited_by), user_preferences (user_id), user_roles (user_id), user_security (user_id), user_sessions (user_id)

Indexes

  • idx_users_last_login (last_login_at)
  • idx_users_org_code (org_code)
  • idx_users_organization (organization_id)
  • idx_users_status (status)
  • uq_users_org_email (organization_id, lower((email)::text)) UNIQUE WHERE (deleted_at IS NULL)
  • ux_users_active_email (lower((email)::text)) UNIQUE WHERE ((deleted_at IS NULL) AND ((status) = 'ACTIVE'))
  • ux_users_email_active (lower((email)::text)) UNIQUE WHERE (deleted_at IS NULL)

user_security​

One-to-one security state for a user: failed-login lockout, password expiry/reset, and email-verification tokens (hashed).

ColumnTypeNullDefaultNotes
user_idbigintNOPK; FK → users.id (ON DELETE CASCADE)
failed_login_attemptsintegerNO0
locked_untiltimestamptzYES
password_changed_attimestamptzYES
password_expires_attimestamptzYES
last_password_reset_attimestamptzYES
email_verification_code_hashvarchar(255)YES
email_verification_expires_attimestamptzYES
email_verification_attemptsintegerNO0
email_verified_attimestamptzYES
password_reset_token_hashvarchar(255)YES
password_reset_expires_attimestamptzYES
email_verification_sent_attimestamptzYES

Table constraints

  • CHECK chk_failed_login_attempts: (failed_login_attempts >= 0)

user_sessions​

Refresh-token sessions per user/device, with expiry, last activity and revocation time.

ColumnTypeNullDefaultNotes
idbigintNOPK
user_idbigintNOFK → users.id (ON DELETE CASCADE)
refresh_token_hashvarchar(255)NOUNIQUE
last_activity_attimestamptzNOCURRENT_TIMESTAMP
expires_attimestamptzNO
revoked_attimestamptzYES
device_idvarchar(255)YES
created_attimestamptzNOCURRENT_TIMESTAMP

Indexes

  • idx_user_sessions_active (user_id, expires_at) WHERE (revoked_at IS NULL)
  • idx_user_sessions_expires (expires_at)
  • idx_user_sessions_user (user_id)

user_preferences​

Per-user UI preferences (currently page size) scoped by organization and preference type.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
user_idbigintNOFK → users.id (ON DELETE CASCADE); UNIQUE
page_sizeintegerNO10
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
organization_iduuidNOFK → organizations.id (ON DELETE CASCADE)
preference_typevarchar(50)YES

Table constraints

  • CHECK user_preferences_page_size_check: ((page_size >= 1) AND (page_size <= 200))

Indexes

  • ux_user_preferences_org_user_type (organization_id, user_id, preference_type) UNIQUE

roles​

Roles used for access control. System roles (organization NULL) are shared by all tenants; organizations may define their own.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidYESFK → organizations.id (ON DELETE CASCADE); UNIQUE with role_name
role_namevarchar(100)NOUNIQUE with organization_id
descriptiontextYES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
org_codevarchar(50)YES
is_system_definedbooleanNOfalse

Table constraints

  • UNIQUE (organization_id, role_name)

Referenced by: organization_invitations (role_id), pending_signups (role_id), role_permissions (role_id), user_roles (role_id)

Indexes

  • idx_roles_is_system_defined (is_system_defined)
  • idx_roles_org_code (org_code)
  • idx_roles_organization (organization_id)
  • idx_roles_status (status)
  • uq_roles_system_role_name (role_name) UNIQUE WHERE (is_system_defined = true)

user_roles​

Assigns roles to users, with assigner and optional expiry.

ColumnTypeNullDefaultNotes
idbigintNOPK
user_idbigintNOFK → users.id (ON DELETE CASCADE); UNIQUE with role_id
role_idbigintNOFK → roles.id (ON DELETE CASCADE); UNIQUE with user_id
assigned_attimestamptzNOCURRENT_TIMESTAMP
assigned_bybigintYESFK → users.id (ON DELETE SET NULL)
expires_attimestamptzYES
organization_iduuidYES
org_codevarchar(50)YES

Table constraints

  • UNIQUE (user_id, role_id)

Indexes

  • idx_user_roles_expires (expires_at)
  • idx_user_roles_org_code (org_code)
  • idx_user_roles_organization (organization_id)
  • idx_user_roles_role (role_id)
  • idx_user_roles_user (user_id)

permissions​

Catalog of named permissions.

ColumnTypeNullDefaultNotes
idbigintNOPK
namevarchar(150)NOUNIQUE
descriptiontextYES

Referenced by: role_permissions (permission_id)

role_permissions​

Many-to-many mapping between roles and permissions.

ColumnTypeNullDefaultNotes
role_idbigintNOPK (composite); FK → roles.id (ON DELETE CASCADE)
permission_idbigintNOPK (composite); FK → permissions.id (ON DELETE CASCADE)

organization_invitations​

Email invitations to join an organization, with hashed token, role to assign, expiry and accepted/revoked timestamps.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK → organizations.id (ON DELETE CASCADE)
org_codevarchar(50)NO
emailvarchar(255)NO
invited_bybigintNOFK → users.id (ON DELETE RESTRICT)
token_hashvarchar(255)NOUNIQUE
expires_attimestamptzNO
accepted_attimestamptzYES
revoked_attimestamptzYES
created_attimestamptzNOCURRENT_TIMESTAMP
rolevarchar(50)NO'Employee'
role_idbigintYESFK → roles.id (ON DELETE RESTRICT)
is_deletedbooleanNOfalse

Referenced by: pending_signups (invitation_id)

Indexes

  • ix_org_invitations_email (lower((email)::text))
  • ix_org_invitations_expires_at (expires_at)
  • ix_org_invitations_invited_by (invited_by)
  • ix_org_invitations_organization (organization_id)
  • ix_org_invitations_pending_email (organization_id, lower((email)::text)) WHERE ((accepted_at IS NULL) AND (revoked_at IS NULL))

pending_signups​

Staging table for self-signup and invited signup until the email OTP is verified. Holds the OTP hash and attempt counter.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
full_namevarchar(200)NO
emailvarchar(255)NO
organization_namevarchar(200)NO
password_hashvarchar(255)NO
email_verification_code_hashvarchar(255)NO
email_verification_sent_attimestamptzNOCURRENT_TIMESTAMP
email_verification_expires_attimestamptzNO
email_verification_attemptsintegerNO0
statusvarchar(30)NO'PENDING'Allowed: PENDING, COMPLETED, CANCELLED
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
signup_typevarchar(20)NO'OPEN'
invitation_iduuidYESFK → organization_invitations.id (ON DELETE CASCADE)
organization_iduuidYESFK → organizations.id (ON DELETE CASCADE)
org_codevarchar(50)YES
role_idbigintYESFK → roles.id (ON DELETE RESTRICT)

Table constraints

  • CHECK chk_pending_signup_attempts: (email_verification_attempts >= 0)

2. Master & Reference Data​

master_categories​

Groups of dropdown/lookup values (e.g. GENDER, PAYMENT_MODE, CURRENCY). System-defined or organization-defined.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidYESFK (composite organization_id, org_code) → organizations(id, code); UNIQUE with code; UNIQUE with name
org_codevarchar(50)YESFK (composite organization_id, org_code) → organizations(id, code)
codevarchar(100)NOUNIQUE with organization_id
namevarchar(150)NOUNIQUE with organization_id
descriptiontextYES
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
is_system_definedbooleanNOfalse
OrganizationIduuidYES
OrgCodetextYES

Table constraints

  • UNIQUE (organization_id, code)
  • UNIQUE (organization_id, name)

Referenced by: master_values (master_category_id)

Indexes

  • idx_master_categories_org_code (org_code)
  • idx_master_categories_organization (organization_id)
  • idx_master_categories_status (status)
  • uq_master_categories_system_code (code) UNIQUE WHERE (is_system_defined = true)
  • uq_master_categories_system_name (name) UNIQUE WHERE (is_system_defined = true)

master_values​

The individual lookup values belonging to a master category. Referenced by many business tables through *_id columns.

ColumnTypeNullDefaultNotes
idbigintNOPK
master_category_idbigintNOFK → master_categories.id (ON DELETE CASCADE)
codevarchar(100)NO
namevarchar(150)NO
descriptiontextYES
display_orderintegerNO0
is_defaultbooleanNOfalse
is_system_definedbooleanNOfalse
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
organization_iduuidYES
org_codevarchar(50)YES
OrganizationIduuidYES
OrgCodetextYES
deleted_attimestampYES
deleted_bybigintYES

Table constraints

  • CHECK chk_master_value_display_order: (display_order >= 0)

Referenced by: Expense (CurrencyId, PaymentModeId, PaymentStatusId), customers (customer_group_id, customer_type_id, industry_id, payment_method_id, payment_terms_id), employees (blood_group_id, employment_type_id, gender_id, marital_status_id, pay_type_id, shift_type_id), income (category_id, currency_id, payment_mode_id, payment_status_id), services (applicable_for_id, category_id, discount_type_id, pricing_type_id, sub_category_id, tax_id, unit_of_measurement_id)

Indexes

  • idx_master_values_category (master_category_id)
  • idx_master_values_display_order (master_category_id, display_order)
  • idx_master_values_status (status)
  • uq_master_value_org_category_code (organization_id, org_code, master_category_id, code) UNIQUE WHERE ((is_system_defined = false) AND (deleted_at IS NULL))
  • uq_master_value_org_category_name (organization_id, org_code, master_category_id, name) UNIQUE WHERE ((is_system_defined = false) AND (deleted_at IS NULL))
  • uq_master_value_system_category_code (master_category_id, code) UNIQUE WHERE (is_system_defined = true)
  • uq_master_value_system_category_name (master_category_id, name) UNIQUE WHERE (is_system_defined = true)

departments​

HR departments. System-defined (shared) or organization-specific.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidYES
org_codevarchar(50)YES
codevarchar(50)NO
namevarchar(150)NO
descriptiontextYES
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
is_system_definedbooleanNOfalse

Table constraints

  • CHECK chk_departments_scope: (((is_system_defined = true) AND (organization_id IS NULL) AND (org_code IS NULL)) OR ((is_system_defined = false) AND (organization_id IS NOT NULL) AND (org_code IS NOT NULL)))

Referenced by: employees (department_id)

Indexes

  • idx_departments_is_system_defined (is_system_defined)
  • idx_departments_organization (organization_id)
  • idx_departments_status (status)
  • uq_departments_org_code (organization_id, code) UNIQUE WHERE (is_system_defined = false)
  • uq_departments_org_name (organization_id, name) UNIQUE WHERE (is_system_defined = false)
  • uq_departments_system_code (code) UNIQUE WHERE (is_system_defined = true)
  • uq_departments_system_name (name) UNIQUE WHERE (is_system_defined = true)

designations​

Job titles/designations. System-defined (shared) or organization-specific.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidYESFK (composite organization_id, org_code) → organizations(id, code)
org_codevarchar(50)YESFK (composite organization_id, org_code) → organizations(id, code)
codevarchar(50)NO
namevarchar(150)NO
descriptiontextYES
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
is_system_definedbooleanNOfalse

Table constraints

  • CHECK chk_designations_scope: (((is_system_defined = true) AND (organization_id IS NULL) AND (org_code IS NULL)) OR ((is_system_defined = false) AND (organization_id IS NOT NULL) AND (org_code IS NOT NULL)))

Referenced by: employees (designation_id)

Indexes

  • idx_designations_is_system_defined (is_system_defined)
  • idx_designations_organization (organization_id)
  • idx_designations_status (status)
  • uq_designations_org_code (organization_id, code) UNIQUE WHERE (is_system_defined = false)
  • uq_designations_org_name (organization_id, name) UNIQUE WHERE (is_system_defined = false)
  • uq_designations_system_code (code) UNIQUE WHERE (is_system_defined = true)
  • uq_designations_system_name (name) UNIQUE WHERE (is_system_defined = true)

work_locations​

Work sites/offices used by employees and wages.

ColumnTypeNullDefaultNotes
idbigintNOPK
organization_iduuidYES
org_codevarchar(50)YES
codevarchar(50)NO
namevarchar(150)NO
descriptiontextYES
addresstextYES
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
system_definedbooleanNOfalse

Referenced by: employees (work_location_id)

Indexes

  • idx_work_locations_organization (organization_id)
  • idx_work_locations_status (status)
  • uq_work_locations_org_code (organization_id, code) UNIQUE WHERE (organization_id IS NOT NULL)
  • uq_work_locations_org_name (organization_id, name) UNIQUE WHERE (organization_id IS NOT NULL)

3. HR​

employees​

Employee master record: personal, contact, job, pay and emergency details. Supports a reporting-manager hierarchy through a self-reference.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK (composite organization_id, org_code) → organizations(id, code); UNIQUE with employee_code
org_codevarchar(50)NOFK (composite organization_id, org_code) → organizations(id, code)
employee_codevarchar(50)NOUNIQUE with organization_id
full_namevarchar(200)NO
date_of_birthdateYES
gender_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category GENDER
father_guardian_namevarchar(200)YES
marital_status_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category MARITAL_STATUS
blood_group_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category BLOOD_GROUP
nationalityvarchar(100)YES
phone_numbervarchar(30)NO
alternate_phonevarchar(30)YES
emailvarchar(255)YES
whatsapp_numbervarchar(30)YES
current_addresstextYES
permanent_addresstextYES
department_idbigintYESFK → departments.id (ON DELETE RESTRICT)
designation_idbigintNOFK → designations.id (ON DELETE RESTRICT)
date_of_joiningdateNO
employment_type_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category EMPLOYMENT_TYPE
reporting_manager_iduuidYESFK → employees.id (ON DELETE SET NULL)
work_location_idbigintYESFK → work_locations.id (ON DELETE RESTRICT)
pay_type_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category PAY_TYPE
salary_amountnumeric(18,2)NO
government_idvarchar(50)YES
pan_numbervarchar(20)YES
bank_namevarchar(150)YES
bank_account_numbervarchar(50)YES
ifsc_codevarchar(20)YES
account_holder_namevarchar(200)YES
emergency_contact_namevarchar(200)YES
emergency_contact_numbervarchar(30)YES
profile_image_urltextYES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, ON_LEAVE, TERMINATED
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYESFK → users.id (ON DELETE SET NULL)
updated_bybigintYESFK → users.id (ON DELETE SET NULL)
deleted_attimestamptzYES
shift_type_idbigintYESFK → master_values.id (ON DELETE NO ACTION); category SHIFT_TYPE

Table constraints

  • UNIQUE (organization_id, employee_code)
  • CHECK chk_employee_salary: (salary_amount >= 0)

Referenced by: attendance (employee_id), employee_documents (employee_id), employee_photos (employee_id), employees (reporting_manager_id)

Indexes

  • idx_employees_date_of_joining (date_of_joining)
  • idx_employees_department (department_id)
  • idx_employees_designation (designation_id)
  • idx_employees_email (email)
  • idx_employees_full_name (full_name)
  • idx_employees_org_code (org_code)
  • idx_employees_organization (organization_id)
  • idx_employees_phone (phone_number)
  • idx_employees_reporting_manager (reporting_manager_id)
  • idx_employees_status (status)
  • idx_employees_work_location (work_location_id)

employee_photos​

Employee photo stored as binary data (one per employee).

ColumnTypeNullDefaultNotes
employee_iduuidNOPK; FK → employees.id (ON DELETE CASCADE)
file_nametextNO
content_typetextNO
file_sizebigintNO
file_databyteaNO
created_attimestamptzNO
updated_attimestamptzNO

Table constraints

  • CHECK ck_employee_photos_file_size: (file_size > 0)

employee_documents​

Uploaded employee documents stored as binary data (one per document type per employee).

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
employee_iduuidNOFK → employees.id (ON DELETE CASCADE); UNIQUE with document_type
document_typetextNOUNIQUE with employee_id
file_nametextNO
content_typetextNO
file_sizebigintNO
file_databyteaNO
created_attimestamptzNO
updated_attimestamptzNO

Table constraints

  • UNIQUE (employee_id, document_type)
  • CHECK ck_employee_documents_file_size: (file_size > 0)

Indexes

  • ix_employee_documents_employee_id (employee_id)

attendance​

Daily attendance per employee (status, in/out time, break minutes). One active row per employee per day.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK → organizations.id (ON DELETE CASCADE)
org_codetextYES
employee_iduuidNOFK → employees.id (ON DELETE CASCADE)
attendance_datedateNO
shift_type_idbigintYES
in_timetextYES
out_timetextYES
break_minutesintegerNO0
statustextNO'PRESENT'
remarkstextYES
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
deleted_attimestamptzYES

Indexes

  • idx_attendance_organization_employee_date (organization_id, employee_id, attendance_date)
  • ux_attendance_org_employee_date (organization_id, employee_id, attendance_date) UNIQUE WHERE (deleted_at IS NULL)

wages​

Wage/payroll records per employee and pay period: base wage, overtime, allowances, deductions, net payable, and payment details.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNO
org_codevarchar(50)YES
employee_iduuidNO
start_datedateNO
end_datedateNO
wage_type_idbigintNO
work_location_idbigintYES
payment_status_idbigintNO
working_daysnumeric(18,2)YES
paid_unitsnumeric(18,2)YES
overtimenumeric(18,2)YES
overtime_ratenumeric(18,2)YES
overtime_amountnumeric(18,2)YES
base_wagenumeric(18,2)NO
allowancesnumeric(18,2)YES
advance_recoverynumeric(18,2)YES
other_deductionsnumeric(18,2)YES
basic_wagenumeric(18,2)YES
gross_earningsnumeric(18,2)YES
total_deductionsnumeric(18,2)YES
net_payablenumeric(18,2)YES
payment_datedateNO
payment_method_idbigintNO
payment_account_iduuidYES
transaction_numbervarchar(255)YES
remarkstextYES
payslip_file_namevarchar(255)YES
statusvarchar(20)NO'ACTIVE'
created_attimestamptzNOnow()
updated_attimestamptzNOnow()
created_bybigintYES
updated_bybigintYES
deleted_attimestamptzYES

Indexes

  • ix_wages_employee_id (employee_id)
  • ix_wages_organization_id (organization_id)

4. Customers, Services & Income​

customers​

Customer master: contact details, billing/service addresses, GSTIN/PAN, payment terms and credit limit.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK (composite organization_id, org_code) → organizations(id, code); UNIQUE with customer_code
org_codevarchar(50)NOFK (composite organization_id, org_code) → organizations(id, code)
customer_codevarchar(50)NOUNIQUE with organization_id
namevarchar(200)NO
customer_type_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category CUSTOMER_TYPE
industry_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category INDUSTRY
customer_group_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category CUSTOMER_GROUP
customer_sincedateYES
primary_contact_personvarchar(200)YES
emailvarchar(255)NO
phone_numbervarchar(30)NO
alternate_phonevarchar(30)YES
websitevarchar(255)YES
billing_addresstextYES
service_site_addresstextYES
gstinvarchar(30)YES
panvarchar(20)YES
payment_terms_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_TERMS
credit_limitnumeric(18,2)YES
currency_codevarchar(10)YES
payment_method_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_METHOD
landmarkvarchar(200)YES
cityvarchar(100)YES
statevarchar(100)YES
countryvarchar(100)YES
pincodevarchar(20)YES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, SUSPENDED
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYESFK → users.id (ON DELETE SET NULL)
updated_bybigintYESFK → users.id (ON DELETE SET NULL)
deleted_attimestamptzYES
display_trading_namevarchar(255)YES
billing_cityvarchar(120)YES
billing_statevarchar(120)YES
billing_pincodevarchar(20)YES
billing_countryvarchar(120)YES
same_as_billingbooleanNOfalse
service_cityvarchar(120)YES
service_statevarchar(120)YES
service_pincodevarchar(20)YES
service_countryvarchar(120)YES
preferred_contact_modevarchar(255)YES
notestextYES

Table constraints

  • UNIQUE (organization_id, customer_code)
  • CHECK chk_customers_credit_limit: ((credit_limit IS NULL) OR (credit_limit >= 0))

Referenced by: income (customer_id)

services​

Service catalog: pricing type, unit, default rate, cost, minimum charge, tax and discount rules.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK (composite organization_id, org_code) → organizations(id, code); UNIQUE with code; UNIQUE with name
org_codevarchar(50)NOFK (composite organization_id, org_code) → organizations(id, code)
codevarchar(50)NOUNIQUE with organization_id
namevarchar(150)NOUNIQUE with organization_id
category_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category SERVICE_CATEGORY
sub_category_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category SERVICE_SUB_CATEGORY
pricing_type_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category PRICING_TYPE
unit_of_measurement_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category UNIT_OF_MEASUREMENT
discount_allowedbooleanNOfalse
default_ratenumeric(18,2)NO0
costnumeric(18,2)YES
minimum_chargenumeric(18,2)NO0
tax_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category TAX_GST
descriptiontextYES
estimated_durationvarchar(100)YES
applicable_for_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category APPLICABLE_FOR
statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES
is_deletedbooleanNOfalse
deleted_attimestamptzYES
deleted_bybigintYES
discount_type_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category DISCOUNT_TYPE

Table constraints

  • UNIQUE (organization_id, code)
  • UNIQUE (organization_id, name)
  • CHECK chk_services_cost: ((cost IS NULL) OR (cost >= 0))
  • CHECK chk_services_default_rate: (default_rate >= 0)
  • CHECK chk_services_minimum_charge: (minimum_charge >= 0)

Referenced by: income (service_id)

Indexes

  • idx_services_category (category_id)
  • idx_services_is_deleted (is_deleted)
  • idx_services_org_code (org_code)
  • idx_services_organization (organization_id)
  • idx_services_pricing_type (pricing_type_id)
  • idx_services_status (status)
  • idx_services_sub_category (sub_category_id)
  • idx_services_unit (unit_of_measurement_id)

income​

Income (sales/invoice) records for customers, with tax breakup, payment status/mode and optional service and account.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organization_iduuidNOFK → organizations.id (ON DELETE RESTRICT); UNIQUE with income_number
income_numbervarchar(50)NOUNIQUE with organization_id
income_datedateNO
customer_iduuidNOFK → customers.id (ON DELETE RESTRICT)
service_iduuidYESFK → services.id (ON DELETE RESTRICT)
category_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category INCOME_CATEGORY
currency_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category CURRENCY
amount_before_taxnumeric(18,2)NO0
tax_percentagenumeric(5,2)NO0
tax_amountnumeric(18,2)NO0
total_amountnumeric(18,2)NO0
payment_mode_idbigintYESFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_MODE
account_iduuidYESFK → organizationaccount.id (ON DELETE RESTRICT)
payment_status_idbigintNOFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_STATUS
payment_datedateYES
transaction_referencevarchar(255)YES
invoice_referencevarchar(255)YES
payment_referencevarchar(255)YES
descriptiontextYES
statusvarchar(20)NO'ACTIVE'
created_attimestamptzNOCURRENT_TIMESTAMP
updated_attimestamptzNOCURRENT_TIMESTAMP
created_bybigintYES
updated_bybigintYES

Table constraints

  • UNIQUE (organization_id, income_number)
  • CHECK chk_income_amount_before_tax: (amount_before_tax >= 0)
  • CHECK chk_income_tax_amount: (tax_amount >= 0)
  • CHECK chk_income_tax_percentage: ((tax_percentage >= 0) AND (tax_percentage <= 100))
  • CHECK chk_income_total_amount: (total_amount >= 0)

Indexes

  • idx_income_account (account_id)
  • idx_income_category (category_id)
  • idx_income_customer (customer_id)
  • idx_income_income_date (income_date)
  • idx_income_organization (organization_id)
  • idx_income_payment_date (payment_date)
  • idx_income_payment_mode (payment_mode_id)
  • idx_income_payment_status (payment_status_id)
  • idx_income_service (service_id)
  • idx_income_status (status)

5. Expenses​

ExpenseCategories​

Expense categories, system-defined or organization-defined.

ColumnTypeNullDefaultNotes
IduuidNOgen_random_uuid()PK
OrganizationIduuidYESFK → organizations.id (ON DELETE CASCADE)
Codevarchar(100)NO
Namevarchar(150)NO
DescriptiontextYES
IsSystemDefinedbooleanNOfalse
Statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
CreatedAttimestamptzNOCURRENT_TIMESTAMP
UpdatedAttimestamptzNOCURRENT_TIMESTAMP
CreatedBybigintYES
UpdatedBybigintYES
DeletedAttimestamptzYES

Referenced by: Expense (CategoryId)

Indexes

  • "ExpenseCategoriesOrganizationCodeUnique" (OrganizationId, Code) UNIQUE WHERE (("IsSystemDefined" = false) AND ("DeletedAt" IS NULL))
  • "ExpenseCategoriesOrganizationIndex" (OrganizationId)
  • "ExpenseCategoriesOrganizationNameUnique" (OrganizationId, Name) UNIQUE WHERE (("IsSystemDefined" = false) AND ("DeletedAt" IS NULL))
  • "ExpenseCategoriesStatusIndex" (Status)
  • "ExpenseCategoriesSystemCodeUnique" (Code) UNIQUE WHERE ("IsSystemDefined" = true)
  • "ExpenseCategoriesSystemDefinedIndex" (IsSystemDefined)
  • "ExpenseCategoriesSystemNameUnique" (Name) UNIQUE WHERE ("IsSystemDefined" = true)

ExpensePayees​

Vendors/payees that expenses are paid to.

ColumnTypeNullDefaultNotes
IduuidNOgen_random_uuid()PK
OrganizationIduuidNOFK → organizations.id (ON DELETE CASCADE)
Namevarchar(200)NO
Codevarchar(100)YES
Emailvarchar(255)YES
Phonevarchar(50)YES
AddresstextYES
DescriptiontextYES
Statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, INACTIVE
CreatedAttimestamptzNOCURRENT_TIMESTAMP
UpdatedAttimestamptzNOCURRENT_TIMESTAMP
CreatedBybigintYES
UpdatedBybigintYES

Referenced by: Expense (VendorPayeeId)

Indexes

  • "ExpensePayeesOrganizationCodeUnique" (OrganizationId, Code) UNIQUE WHERE ("Code" IS NOT NULL)
  • "ExpensePayeesOrganizationIndex" (OrganizationId)
  • "ExpensePayeesOrganizationNameUnique" (OrganizationId, Name) UNIQUE
  • "ExpensePayeesStatusIndex" (Status)

Expense​

Expense records with tax breakup, payment status/mode, due/payment dates and reimbursable/deductible/recurring flags.

ColumnTypeNullDefaultNotes
IduuidNOgen_random_uuid()PK
OrganizationIduuidNOFK → organizations.id (ON DELETE RESTRICT); UNIQUE with ExpenseNumber
ExpenseNumbervarchar(50)NOUNIQUE with OrganizationId
ExpenseDatedateNO
CategoryIduuidNOFK → ExpenseCategories.Id (ON DELETE RESTRICT)
VendorPayeeIduuidNOFK → ExpensePayees.Id (ON DELETE RESTRICT)
CurrencyIdbigintNOFK → master_values.id (ON DELETE RESTRICT); category CURRENCY
AmountBeforeTaxnumeric(18,2)NO0
TaxPercentagenumeric(5,2)NO0
TaxAmountnumeric(18,2)NO0
TotalAmountnumeric(18,2)NO0
PaymentModeIdbigintNOFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_MODE
AccountIduuidYESFK → organizationaccount.id (ON DELETE RESTRICT)
TransactionReferencevarchar(255)YES
PaymentStatusIdbigintNOFK → master_values.id (ON DELETE RESTRICT); category PAYMENT_STATUS
PaymentDatedateYES
DueDatedateYES
ServiceJobWorkOrdervarchar(255)YES
InvoiceReferencevarchar(255)YES
DescriptiontextYES
IsReimbursablebooleanNOfalse
IsTaxDeductiblebooleanNOfalse
IsRecurringbooleanNOfalse
Statusvarchar(20)NO'ACTIVE'Allowed: ACTIVE, CANCELLED, INACTIVE
CreatedAttimestamptzNOCURRENT_TIMESTAMP
UpdatedAttimestamptzNOCURRENT_TIMESTAMP
CreatedBybigintYES
UpdatedBybigintYES

Table constraints

  • UNIQUE (OrganizationId, ExpenseNumber)
  • CHECK ChkExpenseAmountBeforeTax: ("AmountBeforeTax" >= 0)
  • CHECK ChkExpenseTaxAmount: ("TaxAmount" >= 0)
  • CHECK ChkExpenseTaxPercentage: (("TaxPercentage" >= 0) AND ("TaxPercentage" <= 100))
  • CHECK ChkExpenseTotalAmount: ("TotalAmount" >= 0)

Indexes

  • "IdxExpenseAccount" (AccountId)
  • "IdxExpenseCategory" (CategoryId)
  • "IdxExpenseCurrency" (CurrencyId)
  • "IdxExpenseDueDate" (DueDate)
  • "IdxExpenseExpenseDate" (ExpenseDate)
  • "IdxExpenseOrganization" (OrganizationId)
  • "IdxExpensePaymentDate" (PaymentDate)
  • "IdxExpensePaymentMode" (PaymentModeId)
  • "IdxExpensePaymentStatus" (PaymentStatusId)
  • "IdxExpenseStatus" (Status)
  • "IdxExpenseVendorPayee" (VendorPayeeId)

6. Accounts & Payments​

organizationaccount​

Parent record for every money account of an organization. accounttype (BANK, DEBIT_CARD, CREDIT_CARD, WALLET) decides which detail table holds its data.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationiduuidNOFK → organizations.id (ON DELETE CASCADE)
accountnametextNO
accounttypevarchar(30)NOAllowed: BANK, DEBIT_CARD, CREDIT_CARD, WALLET
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, DELETED
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP
createdbybigintYES
updatedbybigintYES
is_deletedbooleanNOfalse
deleted_attimestamptzYES
deleted_bybigintYESFK → users.id (ON DELETE RESTRICT)

Referenced by: Expense (AccountId), income (account_id), bankaccountdetails (organizationaccountid), creditcarddetails (organizationaccountid), debitcarddetails (organizationaccountid), walletdetails (organizationaccountid)

Indexes

  • idx_organizationaccount_is_deleted (is_deleted)
  • ixorganizationaccountorganization (organizationid)
  • ixorganizationaccountstatus (status)
  • ixorganizationaccounttype (accounttype)

bankaccountdetails​

Bank account details for an account of type BANK. Sensitive fields are stored encrypted with searchable hashes.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationaccountiduuidNOFK → organizationaccount.id (ON DELETE CASCADE); UNIQUE
banknameencryptedtextNO
banknamehashvarchar(64)YES
accountnumberencryptedtextNO
accountnumberhashvarchar(64)YES
branchcodeencryptedtextYES
branchcodehashvarchar(64)YES
ifsccodeencryptedtextNO
ifsccodehashvarchar(64)YES
branchnameencryptedtextYES
initialamountencryptedtextYES
accounttypevarchar(50)YES
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP
is_primarybooleanNOfalse

debitcarddetails​

Debit card details for an account of type DEBIT_CARD (token, hash, last four digits, expiry, network).

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationaccountiduuidNOFK → organizationaccount.id (ON DELETE CASCADE); UNIQUE
cardholdernameencryptedtextNO
cardnumbertokentextYES
cardnumberhashvarchar(64)YES
lastfourdigitsvarchar(4)YES
expirymonthsmallintYES
expiryyearsmallintYES
banknameencryptedtextYES
cardnetworkvarchar(30)YES
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP

Table constraints

  • CHECK ckdebitcardlastfour: ((lastfourdigits IS NULL) OR ((lastfourdigits) ~ '^[0-9]{4}$'))

creditcarddetails​

Credit card details for an account of type CREDIT_CARD, including encrypted limits.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationaccountiduuidNOFK → organizationaccount.id (ON DELETE CASCADE); UNIQUE
cardholdernameencryptedtextNO
cardnumbertokentextYES
cardnumberhashvarchar(64)YES
lastfourdigitsvarchar(4)YES
expirymonthsmallintYES
expiryyearsmallintYES
banknameencryptedtextYES
cardnetworkvarchar(30)YES
creditlimitencryptedtextYES
availablelimitencryptedtextYES
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP

Table constraints

  • CHECK ckcreditcardlastfour: ((lastfourdigits IS NULL) OR ((lastfourdigits) ~ '^[0-9]{4}$'))

walletdetails​

Wallet details for an account of type WALLET. Sensitive fields are stored encrypted.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationaccountiduuidNOFK → organizationaccount.id (ON DELETE CASCADE); UNIQUE
walletproviderencryptedtextNO
walletidentifierencryptedtextYES
walletidentifierhashvarchar(64)YES
holdernameencryptedtextYES
initialamountencryptedtextYES
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP

payment​

Payment ledger entries (received/paid) with party, reference, amount, mode and optional attachment.

ColumnTypeNullDefaultNotes
iduuidNOgen_random_uuid()PK
organizationiduuidNOFK → organizations.id (ON DELETE CASCADE)
paymentnumbertextNO
paymentdatedateNO
paymenttypevarchar(30)NO
partytextNO
referencetypevarchar(30)NO
referencenumbertextYES
amountnumeric(14,2)NO
paymentmodetextNO
transactionreferencetextYES
notestextYES
attachmentnametextYES
attachmentpathtextYES
statusvarchar(30)NO'ACTIVE'Allowed: ACTIVE, INACTIVE, DELETED
createdattimestamptzNOCURRENT_TIMESTAMP
updatedattimestamptzNOCURRENT_TIMESTAMP
createdbybigintYES
updatedbybigintYES
is_deletedbooleanNOfalse
deleted_attimestamptzYES
deleted_bybigintYESFK → users.id (ON DELETE RESTRICT)

Table constraints

  • CHECK ckpaymentamountpositive: (amount > 0)

Indexes

  • idx_payment_is_deleted (is_deleted)
  • ixpaymentdate (paymentdate)
  • ixpaymentorganization (organizationid)
  • ixpaymentstatus (status)
  • ixpaymenttype (paymenttype)
  • uqpaymentnumberperorg (organizationid, paymentnumber) UNIQUE

7. System​

__EFMigrationsHistory​

Entity Framework Core migration tracking table. Managed by the framework; not a business table.

ColumnTypeNullDefaultNotes
MigrationIdvarchar(150)NOPK
ProductVersionvarchar(32)NO

6. Master Data Catalog​

master_categories defines the dropdown groups and master_values holds the values. The Used by column was derived from the foreign-key columns and the data they reference.

IDCategory codeNameSystem valuesOrg valuesUsed by
1CUSTOMER_TYPECustomer Type323customers.customer_type_id
2CUSTOMER_GROUPCustomer Group / Segment42customers.customer_group_id
3INDUSTRYIndustry / Category732customers.industry_id
4PAYMENT_TERMSPayment Terms52customers.payment_terms_id
5PAYMENT_METHODPreferred Payment Method51customers.payment_method_id
6CONTACT_MODEPreferred Contact Mode40—
7GENDERGender40employees.gender_id
8MARITAL_STATUSMarital Status40employees.marital_status_id
9BLOOD_GROUPBlood Group80employees.blood_group_id
10EMPLOYMENT_TYPEEmployment Type40employees.employment_type_id
11PAY_TYPEPay Type30employees.pay_type_id
13SERVICE_CATEGORYService Category35services.category_id
14SERVICE_SUB_CATEGORYService Sub Category33services.sub_category_id
15PRICING_TYPEPricing Type33services.pricing_type_id
16UNIT_OF_MEASUREMENTUnit of Measurement34services.unit_of_measurement_id
17APPLICABLE_FORApplicable For36services.applicable_for_id
18INCOME_CATEGORYIncome Category623income.category_id
19PAYMENT_MODEPayment Mode835Expense.PaymentModeId, income.payment_mode_id
20PAYMENT_STATUSPayment Status24Expense.PaymentStatusId, income.payment_status_id
21CURRENCYCurrency144Expense.CurrencyId, income.currency_id
22SHIFT_TYPEShift Type40employees.shift_type_id
23TAX_GSTTax / GST60services.tax_id
24DISCOUNT_TYPEDiscount Type20services.discount_type_id
28EXPENSE_CATEGORYExpense Category100—
29EXPENSE_VENDORVendor / Payee40—
30EXPENSE_ACCOUNT_TYPEAccount Type50—
31WAGE_TYPEWage Type40—
33PAYMENT_TYPEPayment Type29—
34PARTYParty43—
35REFERENCE_TYPEReference Type44—

Categories with no entry under Used by (CONTACT_MODE, EXPENSE_CATEGORY, EXPENSE_VENDOR, EXPENSE_ACCOUNT_TYPE, WAGE_TYPE, PAYMENT_TYPE, PARTY, REFERENCE_TYPE) are not linked through a foreign key. They are consumed by application logic or stored as text (for example the payment table).

7. Status and Enumerated Values​

Table.columnAllowed values
Expense.StatusACTIVE, CANCELLED, INACTIVE
ExpenseCategories.StatusACTIVE, INACTIVE
ExpensePayees.StatusACTIVE, INACTIVE
customers.statusACTIVE, INACTIVE, SUSPENDED
departments.statusACTIVE, INACTIVE
designations.statusACTIVE, INACTIVE
employees.statusACTIVE, INACTIVE, ON_LEAVE, TERMINATED
master_categories.statusACTIVE, INACTIVE
master_values.statusACTIVE, INACTIVE
organizationaccount.statusACTIVE, INACTIVE, DELETED
organizationaccount.accounttypeBANK, DEBIT_CARD, CREDIT_CARD, WALLET
organizations.statusACTIVE, INACTIVE, SUSPENDED
payment.statusACTIVE, INACTIVE, DELETED
pending_signups.statusPENDING, COMPLETED, CANCELLED
roles.statusACTIVE, INACTIVE
services.statusACTIVE, INACTIVE
users.statusACTIVE, INACTIVE, PENDING, SUSPENDED
work_locations.statusACTIVE, INACTIVE

Other fixed value set: pending_signups.signup_type (OPEN, INVITED).

8. Stored Routines​

RoutineTypeDescription
fn_get_organization_master_data(p_organization_id uuid)Function → jsonbValidates that the organization is active and not deleted, then returns the roles and master values (system-defined plus that organization's own) as one JSON document for the frontend.
sp_get_departments(p_organization_id uuid)Function → tableReturns active departments: all system-defined ones plus those of the given organization, ordered by name.
sp_create_pending_signup(...)ProcedureStarts a signup. Validates name, email and signup type (OPEN or INVITED), rejects emails that already belong to an active user, and creates or refreshes a PENDING row in pending_signups with a new OTP hash and expiry. For INVITED signups it also validates the invitation and role. Returns p_success and p_message. Two overloads exist: an older one (open signup only) and a newer one with signup type, organization, invitation and role parameters.
sp_verify_and_complete_signup(p_email, p_otp_hash, p_max_attempts, ...)ProcedureCompletes a signup after OTP entry. Checks that the pending signup exists, is not expired, is under the attempt limit and that the OTP hash matches (a wrong code increments email_verification_attempts). For OPEN signups it creates a new organization with an auto-generated code (first three letters of the name plus four random digits); for INVITED signups it re-validates the invitation and joins the existing organization. Returns p_success and p_message.

9. Planned Changes​

Items below are known gaps and improvements to be handled later. They do not affect current behaviour.

#AreaCurrent stateProposed change
1Organization foreign keysdepartments, work_locations and master_values have organization_id but no foreign key to organizations (designations has a composite one).Add foreign keys (and the composite (organization_id, org_code) key where org_code exists) to match designations, customers and employees.
2Duplicate columnsmaster_categories and master_values contain both organization_id/org_code and "OrganizationId"/"OrgCode", apparently left over from an EF migration. master_values.deleted_at is timestamp while other tables use timestamptz.Remove the duplicate PascalCase columns after confirming nothing reads them. Align deleted_at to timestamptz.
3payment lookups stored as textpaymenttype, party, referencetype and paymentmode are free text, although PAYMENT_TYPE, PARTY, REFERENCE_TYPE and PAYMENT_MODE exist as master categories. referencenumber has no foreign key to income or Expense.Store lookup IDs referencing master_values and consider typed references to the source record.
4attendance shift and timesshift_type_id has no foreign key (unlike employees.shift_type_id), and in_time/out_time are text.Add the foreign key to master_values and change the time columns to time or timestamptz.
5Plaintext employee financial dataemployees.bank_account_number, ifsc_code, pan_number and government_id are stored unencrypted, while the account-detail tables encrypt equivalent data.Encrypt these columns, or move them to an encrypted structure like bankaccountdetails.
6user_preferences constraintsUnique on user_id alone conflicts with the unique on (organization_id, user_id, preference_type), so a user can effectively have one row only. Two identical foreign keys exist on user_id.Drop the single-column unique (if multiple preference rows are intended) and one duplicate foreign key.
7Redundant email indexes on usersuq_users_org_email, ux_users_active_email and ux_users_email_active overlap.Keep the indexes that match the intended rule (per-organization or global email uniqueness) and drop the rest.
8Audit-column foreign keyscreated_by/updated_by have foreign keys to users only on users, organizations, employees and customers.Add them consistently, or document that they are informational.
9Session retentionuser_sessions keeps expired and revoked sessions indefinitely.Add a periodic cleanup job based on expires_at / revoked_at.
10Permissions not populatedpermissions and role_permissions have no rows, so access control currently relies on role names.Populate permissions, or remove the tables if they will not be used.
11Naming consistencyThree naming styles are in use (snake_case, PascalCase, run-together lowercase).Standardize on snake_case in a future migration.

Appendix: Viewing the ER Diagrams​

  • Interactive: open opsnexa_er_diagrams.html in a browser (needs internet access to load Mermaid). Each diagram can be downloaded as SVG.
  • Online editor: paste any Mermaid block from Section 3 into Mermaid Live Editor to view and export PNG/SVG.
  • Confluence: use a Mermaid macro app, or insert the exported SVG/PNG.
  • GitHub/GitLab and VS Code (Markdown preview): render Mermaid blocks natively.