Skip to content

Remove Organization model — single-tenant per host instance#31

Merged
HamptonMakes merged 1 commit intomainfrom
remove-organization-model
Feb 26, 2026
Merged

Remove Organization model — single-tenant per host instance#31
HamptonMakes merged 1 commit intomainfrom
remove-organization-model

Conversation

@HamptonMakes
Copy link
Collaborator

Summary

Drop the organizations table and all org-scoping logic from the host app. Multi-tenancy is now achieved by deploying separate host instances rather than org-scoped data.

Changes

  • Migration: removes users.organization_id FK/column, renames org_rolerole, makes email globally unique, drops the organizations table
  • Deleted: Organization model, factory, specs, and ActiveAdmin registration
  • SessionsController: simplified to User.find_or_create_by!(email:) — no more org lookup by email domain
  • User model: removed belongs_to :organization, email_domain_must_be_allowed validation, and org-scoped email uniqueness
  • ActiveAdmin: removed :organization columns/rows from all registrations
  • Seeds: create users directly without organization
  • Specs: updated 23 spec files to remove org references; all 393 specs pass

Engine tables already had organization_id removed in PR #27.

Closes #28

Drop the organizations table and all org-scoping logic from the host app.
Multi-tenancy is now achieved by deploying separate host instances.

- Migration removes users.organization_id FK/column, renames org_role to
  role, makes email globally unique, and drops the organizations table
- Delete Organization model, factory, specs, and ActiveAdmin registration
- Simplify SessionsController to find_or_create_by email directly
- Update User model: remove belongs_to :organization, email_domain
  validation, and org-scoped email uniqueness
- Update all ActiveAdmin registrations to remove organization columns
- Update seeds, factories, and 23 spec files to remove org references

Closes #28

Amp-Thread-ID: https://ampcode.com/threads/T-019c9b6e-727a-7248-b983-1341ff617751
Co-authored-by: Amp <amp@ampcode.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1c8129963

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


rename_column :users, :org_role, :role

add_index :users, :email, unique: true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deduplicate users before adding unique email index

Adding a global unique index on users.email will fail migration on any instance that currently has the same email in multiple organizations, which was previously valid because uniqueness was scoped to organization_id; in that case MySQL will abort db:migrate with a duplicate-key error and block deployment. This migration should either merge/remap duplicates first or guard and fail with an explicit remediation path.

Useful? React with 👍 / 👎.

end

user = org.users.find_or_create_by!(email: email) do |u|
user = User.find_or_create_by!(email: email) do |u|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate sign-in email before find_or_create

This now calls find_or_create_by! on raw input without any server-side guard, so a blank/whitespace email (e.g. direct POST that bypasses browser required checks) raises ActiveRecord::RecordInvalid and returns a 500 instead of a handled 4xx response. Please reject invalid input before persistence or rescue and re-render the sign-in form with an error.

Useful? React with 👍 / 👎.

@HamptonMakes HamptonMakes merged commit 8010211 into main Feb 26, 2026
4 checks passed
@HamptonMakes HamptonMakes deleted the remove-organization-model branch February 26, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Organization model entirely

1 participant