Skip to content

Database and security rules ​

Tables ​

TablePurpose
profilesUser name, phone and language
organizationsBusinesses and their settings
membershipsWho belongs to which business, with role and site limits
invitesInvite codes
devicesDevices that used a business
sites, work_types, custom_field_defsLists and custom field definitions
staffStaff profiles without pay rates
staff_compensationPay rates and pay notes (protected)
attendance_entriesDaily attendance
work_entriesDaily work
paymentsPayments and adjustments
period_closingsLocked months
audit_logChange history written by triggers

Most tables have org_id, created_at, updated_at, created_by, updated_by, device_id, revision and deleted_at.

Functions ​

FunctionPurpose
create_organizationCreates a business and makes the caller the Owner
accept_inviteJoins a business with an invite code
delete_my_accountDeletes the account, owned businesses and their audit log
transfer_organization_ownershipMakes another member the Owner (migration 4)
is_org_member, org_role, has_org_roleMembership and role checks
can_view_moneyTrue for Owner, Manager, Accountant, and for Viewers unless payments are hidden from them

Access rules ​

TableReadWriteDelete forever
staff, sites, work_types, custom_field_defsAll membersOwner, ManagerOwner
attendance_entries, work_entriesAll membersOwner, Manager, SupervisorOwner
staff_compensationThose who can view moneyOwner, ManagerOwner
payments, period_closingsThose who can view moneyOwner, Manager, AccountantOwner
audit_logOwner, Manager, AccountantTriggers onlyNone
invitesOwner, ManagerOwner (any role), Manager (Supervisor, Accountant, Viewer)
organizationsMembersOwner
membershipsMembersOwnerOwner or the member

Extra protections ​

  • The last active Owner cannot be removed or demoted.
  • Attendance, work and payments must belong to the same business as their staff member.
  • Invite codes are random, expire and can be revoked.
  • Migration 3 blocks changes to attendance and payments inside a closed month, and only the Owner can unlock.
  • Migration 4 restricts which roles can invite which roles.

Storage ​

Photos and receipts are saved with the records in the version 1.0.0 app.

Changing the database ​

Add a new migration file for every change. Never edit a migration that has already been applied. Test with a second user in each role before release.

Official Documentation Hub for Rozfiber Apps & Platforms