Skip to content

Remove org_id from units, tasks, unit_occupants, rent_config, payment_records — DB, entities, models, and services (Phase 0) #463

@gaaliciA1990

Description

@gaaliciA1990

Summary

org_id has been identified as redundant on several tables because org membership is always derivable via property_id → properties → organizations. This issue tracks the full removal across the DB schema, Supabase entities, shared models, and backend services.

org_id has already been removed from common_areas in the #387 migration. This issue covers the remaining tables.


Database (Supabase migrations)

units

  • Drop idx_units_org_id index
  • Drop units_unit_id_org_id_unique composite unique constraint ← blocks downstream FK removals
  • Drop org_id column

tasks

  • Drop idx_tasks_org_id and idx_tasks_org_status indexes
  • Drop org_scoped_tasks RLS policy (if not already removed)
  • Drop org_id column
  • Add replacement index idx_tasks_property_status ON tasks(property_id, status) WHERE deleted_at IS NULL

unit_occupants

  • Drop composite FK unit_occupants_unit_org_fk (FOREIGN KEY (unit_id, org_id) REFERENCES units(unit_id, org_id))
  • Add simple FK FOREIGN KEY (unit_id) REFERENCES units(unit_id) ON DELETE CASCADE
  • Drop idx_unit_occupants_org_id index
  • Drop unique index idx_unit_occupants_one_active_per_user (includes org_id column) — replace with (user_id) WHERE status = 'ACTIVE' AND user_id IS NOT NULL AND deleted_at IS NULL
  • Drop org_id column

rent_config

  • Drop composite FK rent_config_unit_org_fk (FOREIGN KEY (unit_id, org_id) REFERENCES units(unit_id, org_id))
  • Add simple FK FOREIGN KEY (unit_id) REFERENCES units(unit_id) ON DELETE CASCADE
  • Drop idx_rent_config_org_id index
  • Drop org_id column

payment_records

  • Drop composite FK payment_records_unit_org_fk (FOREIGN KEY (unit_id, org_id) REFERENCES units(unit_id, org_id))
  • Add simple FK FOREIGN KEY (unit_id) REFERENCES units(unit_id) ON DELETE CASCADE
  • Drop idx_payment_records_org_id index
  • Drop org_id column

Migration order: composite FKs on unit_occupants, rent_config, payment_records must be dropped before removing the units_unit_id_org_id_unique constraint, which must be dropped before removing org_id from units.


Backend — Supabase Entities

  • UnitEntity — remove orgId / @SerialName("org_id"); remove from CreateUnitEntity
  • TaskEntity — remove orgId / @SerialName("org_id"); remove from CreateTaskEntity
  • UnitOccupantEntity — remove orgId
  • RentConfigEntity — remove orgId; remove from CreateRentConfigEntity
  • PaymentRecordEntity — remove orgId; remove from CreatePaymentRecordEntity
  • SupabaseMappers.kt — remove orgId from all mapper functions for the above entities

Backend — Domain Models


Shared Models

  • UnitModel.kt — remove orgId: OrganizationId
  • TaskModel.kt — remove orgId (already planned in [BE] TaskController + TaskService + TaskDatastore (Phase 0) #387)
  • UnitOccupantModel.kt — remove orgId
  • RentConfigModel.kt — remove orgId
  • PaymentRecordModel.kt — remove orgId
  • Corresponding *NetworkRequest / *NetworkResponse models — remove orgId fields

Backend — Datastores & Services

For each affected datastore (SupabaseUnitDatastore, SupabaseTaskDatastore, SupabaseUnitOccupantDatastore, SupabaseRentConfigDatastore, SupabasePaymentRecordDatastore):

  • Remove orgId parameter from create* methods
  • Remove orgId filter from get* / list queries

For each affected service:

  • Remove orgId parameter from create* and get* / list methods
  • Update callers in controllers

RBAC

All RBAC resolution already goes through propertyId → property → org. No changes needed to RBACService itself, but verify no service method passes orgId as a scoping argument after the above changes.


Tests

  • Update unit tests for affected services and controllers (remove orgId from mock setups)
  • Update integration tests for affected datastores (remove orgId from create calls and assertions)
  • Update JSON test fixtures that include orgId fields

Notes

  • org_id on documents is independent (not derived from units) — leave as-is for now
  • Monetary Long fields (amount_due, amount_paid, monthly_amount) are intentional (smallest currency unit) — do not treat as migration debt
  • common_areas.org_id has already been removed in migration 20260327000001 (part of [BE] TaskController + TaskService + TaskDatastore (Phase 0) #387)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions