towerops/priv/repo/migrations/20260215233513_add_executive_and_technician_roles.exs
Graham McIntie b4c0407ee0 Add granular org roles: executive, technician
New role system:
- owner: full access + financials
- admin: full access + financials (except org deletion)
- executive: read-only + full financial visibility (MRR, revenue)
- technician: field ops (devices, sites, alerts) without financials
- member: legacy alias for technician (migrated)
- viewer: read-only, no financials

Financial data (MRR, revenue, billing) gated behind can_view_financials
assign in all LiveView templates: dashboard, alerts, trace, site show.

Includes migration to rename existing member roles to technician.
2026-02-15 17:40:53 -06:00

30 lines
1.2 KiB
Elixir

defmodule Towerops.Repo.Migrations.AddExecutiveAndTechnicianRoles do
use Ecto.Migration
@moduledoc """
Migrates existing 'member' roles to 'technician'.
The role column is a varchar (Ecto.Enum handles validation in app code),
so no DDL changes needed — just data migration.
New roles added:
- 'executive' — read-only with full financial visibility
- 'technician' — replaces 'member', field ops without financial access
"""
def up do
# Migrate existing 'member' memberships to 'technician'
execute "UPDATE organization_memberships SET role = 'technician' WHERE role = 'member'"
execute "UPDATE organization_invitations SET role = 'technician' WHERE role = 'member'"
end
def down do
# Revert technician back to member
execute "UPDATE organization_memberships SET role = 'member' WHERE role = 'technician'"
execute "UPDATE organization_invitations SET role = 'member' WHERE role = 'technician'"
# Revert executive to admin (closest equivalent)
execute "UPDATE organization_memberships SET role = 'admin' WHERE role = 'executive'"
execute "UPDATE organization_invitations SET role = 'admin' WHERE role = 'executive'"
end
end