Remove Organization model — single-tenant per host instance#31
Remove Organization model — single-tenant per host instance#31HamptonMakes merged 1 commit intomainfrom
Conversation
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>
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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| |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Drop the
organizationstable 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
users.organization_idFK/column, renamesorg_role→role, makes email globally unique, drops theorganizationstableOrganizationmodel, factory, specs, and ActiveAdmin registrationUser.find_or_create_by!(email:)— no more org lookup by email domainbelongs_to :organization,email_domain_must_be_allowedvalidation, and org-scoped email uniqueness:organizationcolumns/rows from all registrationsEngine tables already had
organization_idremoved in PR #27.Closes #28