@xaramoge/shared-database

v0.1.3

Published

Database types, schemas, and migrations for Xaramoge

Readme

xaramoge Shared Database

Database schemas, migrations, and TypeScript types for xaramoge.

Setup

Local Development

# Initialize Supabase
supabase init

# Link to cloud project
supabase link --project-ref YOUR_PROJECT_REF

# Apply migrations
supabase db push

# Load seed data
supabase db seed

Migrations

Located in supabase/migrations/

  • *_initial_setup.sql - Core schemas (RBAC, clients, inventory, assets)
  • *_helper_functions.sql - RPC functions for frontend

Seed Data

Located in supabase/seed.sql

Creates demo data:

  • 1 organization (Santos Healthcare Group)
  • 3 tenants (Manila, QC, Cebu dialysis clinics)
  • 6 demo users
  • 7 demo patients
  • 10 inventory items
  • 6 assets (dialysis machines, RO system, etc.)

Helper Functions

get_user_accessible_tenants(user_id)

Returns all tenants a user has access to.

has_org_permission(user_id, org_id, permission)

Check organization-level permissions.

has_tenant_permission(user_id, tenant_id, resource, action)

Check tenant-level permissions.

search_clients(tenant_id, query, limit)

Full-text search for clients.

get_low_stock_items(tenant_id)

Get inventory items at/below reorder point.

deduct_inventory(...)

Deduct inventory and log transaction.

get_tenant_dashboard_stats(tenant_id)

Get aggregated dashboard statistics.

Testing

npm run test:connection

License

MIT