The short answer
Introduce an organization that owns the data, make users members of it with a role, move every ownership column from the user to the organization in an expand-and-contract migration, check permissions on the server for every action, and prove with tests that one organization cannot reach another's rows. Keep roles few at first: owner, admin and member cover most needs.
On this page
Your SaaS started with one user per account. Now customers say “my colleague needs access too”. This is a common growth step and a risky one: the app’s data model assumes that a user owns things, and you are about to change that for every table.
What changes in the data model?
Add an organization (also called account, workspace or team) as the owner of data. Users become members of an organization, through a join table with a role.
organizations (id, name, ...)
memberships (organization_id, user_id, role)
invitations (organization_id, email, role, token_hash, expires_at)
Every table that has a user_id meaning “this user’s data” gets an organization_id. Keep created_by where you want to know who made something.
Decide early whether a person can belong to several organizations. If your customers include consultants and agencies, they will. Supporting it later is harder than supporting it now: the app must know which organization is active in each request.
How do you migrate without breaking existing customers?
Use expand and contract. Old and new versions of the app run against the same database during a deploy, so never rename or drop a column in the release that stops using it.
- Expand. Create the organizations and memberships tables. Add a nullable
organization_idto each data table. - Backfill. For each existing user, create a personal organization with the user as owner, and set
organization_idon their rows. Run it in batches and make it safe to rerun. - Dual write. New code writes both columns. Add a check that reports rows where they disagree.
- Switch reads. Queries and permissions use
organization_id. - Contract. In a later release, make
organization_idrequired and remove the old ownership logic.
Each existing customer ends up as a one-member organization, so nobody sees anything change until they invite someone.
Which roles do you need?
Start small. Three roles cover most products:
| Role | Can do |
|---|---|
| Owner | Everything, including billing and deleting the organization |
| Admin | Manage members and settings, all data |
| Member | Work with data, no member or billing management |
Add a read-only role when customers ask for it. Resist custom roles with a matrix of checkboxes until several customers ask for the same thing; each permission is something you must test.
Rules worth writing down: an organization must always have at least one owner; the last owner cannot be removed or demoted; only owners can transfer ownership.
Where do permission checks live?
On the server, in one place. Hiding a button is not security, because anyone can call the API directly. Write a function such as can(user, action, resource) that every endpoint calls, and test it.
Two further rules:
- Check the organization on every query. The most common bug is an endpoint that loads a record by id without confirming it belongs to the user’s organization. Enforce it in the database where you can: PostgreSQL row-level security makes the database refuse cross-organization access whatever the code does. See multi-tenant or single-tenant.
- Let the UI ask. The API can return the actions allowed for a record, and the page shows only those buttons. The same idea works for rules about status; see status columns are state machines.
How do invitations work safely?
- Generate a random token, store only its hash, set an expiry and mark it used once.
- The invited email must match the account that accepts it, or require them to confirm it.
- Let admins revoke pending invitations.
- Rate-limit invitation sending, so the feature cannot be used to send spam.
- Handle both cases: the invitee already has an account, and does not.
What about billing?
Billing moves from user to organization too. Decide whether pricing is per seat, flat or by usage; per seat needs member counting and prorated changes. Keep the payment change in its own release with its own tests, because money bugs cost the most.
What should you test?
- A member of organization A gets nothing from organization B, through every endpoint. Do this as an automated test that goes through the real API, not by hand.
- Each role can do exactly what the table says and no more.
- The last owner cannot be removed.
- An expired or reused invitation fails.
- Removing a member ends their sessions immediately.
- The backfill gives every existing user exactly one organization.
Keep permission and tenant isolation tests permanently. They are the ones you never remove to save time; see proving tenant isolation in CI.
What do customers ask for next?
Once teams exist, expect requests for single sign-on, an audit log of who changed what, per-project permissions and an API for managing members. Do not build them yet, but avoid choices that block them: keep the identity of a person separate from their membership, record the actor on sensitive changes, and keep permission checks in one function. Then each later feature is an addition and not a rewrite of the model you have just migrated.
Working with us
We add organizations, roles and invitations to live products, with the migration planned so current customers notice nothing. Tell us about your current data model and who your customers are through contact, or see our SaaS platform work.