Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

OSAC-1532: Rename organizations table to tenants - #730

Merged
openshift-merge-bot[bot] merged 2 commits into
osac-project:mainfrom
DakCrowder:rename-organizations-table-to-tenants
Jun 22, 2026
Merged

openshift-merge-bot[bot] merged 2 commits into
osac-project:mainfrom
DakCrowder:rename-organizations-table-to-tenants

Conversation

@DakCrowder

@DakCrowder DakCrowder commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Renames the organizations table to tenants.

The golang code is (largely) unmodified outside of an explicit SetTableName func added so that the current organizations code (such as the private server) can sit over the renamed tenants table. This functionality is viewed as temporary as a follow up PR will be put up with broader changes in the fulfillment-service to rename the services themselves from organizations to tenants.

The goal here is no net new behavior, and this change should be opaque to callers of the organizations apis/service.

Assisted-by: Claude Code

Summary by CodeRabbit

  • Refactor

    • Database schema reorganized with updated table structure and naming conventions for consistency
    • Data access abstraction layer enhanced with flexible configuration options for dynamic table mapping
  • Tests

    • New migration validation test suite added to verify schema changes, foreign-key integrity, and column immutability enforcement
    • Existing test suites updated to maintain compatibility with database schema changes

@openshift-ci-robot

openshift-ci-robot commented Jun 18, 2026 •

Copy link
Copy Markdown

@DakCrowder: This pull request references OSAC-1532 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Renames the organizations table to tenants.

The golang code is (largely) unmodified and an explicit SetTableName func added so that the current organizations code (such as the private server) can sit over the renamed tenants table. This functionality is viewed as temporary as a follow up PR will be put up with broader changes in the fulfillment-service to rename the services themselves from organizations to tenants.

The goal here is no net new behavior, and this change should be opaque to callers of the organizations apis/service.

Assisted-by: Claude Code

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from adriengentil and eliorerz June 18, 2026 18:57
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@DakCrowder, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 43 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: bb7e82dc-67e6-4da8-88d7-ea45bfd3349d

📥 Commits

Reviewing files that changed from the base of the PR and between fb3eb58 and a9883cf.

📒 Files selected for processing (2)
  • internal/database/migrations/58_rename_organizations_to_tenants.up.sql
  • internal/database/migrations/58_rename_organizations_to_tenants_test.go

Walkthrough

Migration 58 renames the organizations table (and archived_organizations) to tenants (and archived_tenants) via dynamic DDL that drops and recreates foreign key constraints and the immutability trigger. GenericDAOBuilder and GenericServerBuilder gain a SetTableName override, which is wired through PrivateOrganizationsServer. All affected DAO and server tests are updated accordingly.

Changes

Rename organizations to tenants

Layer / File(s) Summary
Migration 58: rename tables, indexes, triggers, and FKs
internal/database/migrations/58_rename_organizations_to_tenants.up.sql
Drops check_immutable_columns trigger and all FKs referencing organizations, renames tables and indexes, recreates trigger on tenants, and dynamically re-adds FK constraints targeting tenants(id).
Migration 58 test suite
internal/database/migrations/58_rename_organizations_to_tenants_test.go
Validates the migration end-to-end: organizations table removed, archived_tenants present, clusters→tenants FK enforced, and immutability trigger still active.
GenericDAOBuilder SetTableName override
internal/database/dao/generic_dao.go
Adds table field, SetTableName() method, and resolveTableName() helper to GenericDAOBuilder; Build() uses the override when set, otherwise falls back to the protobuf-derived name.
GenericServerBuilder override and organizations server wiring
internal/servers/generic_server.go, internal/servers/private_organizations_server.go
Adds table field and SetTableName() to GenericServerBuilder, propagates it to the DAO builder in Build(), and wires SetTableName("tenants") in both the server and DAO chains of PrivateOrganizationsServerBuilder.
database_tool FK validation updated for tenants
internal/database/database_tool.go
Updates checkTenantForeignKey comment and SQL predicate to require the referenced table to be tenants instead of organizations.
DAO tests retargeted to tenants
internal/database/dao/dao_immutability_test.go, internal/database/dao/generic_dao_events_test.go, internal/database/dao/generic_dao_immutability_test.go, internal/database/dao/generic_dao_integrity_test.go
Seeds, UPDATE targets, and expected trigger error messages updated from organizations to tenants; test setups add explicit SetTableName("tenants").
Server tests add SetTableName for tenant DAO setup
internal/servers/private_projects_server_test.go, internal/servers/private_public_ip_attachments_server_test.go, internal/servers/private_subnets_server_test.go, internal/servers/private_virtual_networks_server_test.go, internal/servers/projects_server_test.go, internal/servers/servers_tenancy_test.go
All server test BeforeEach hooks that construct a GenericDAO[*privatev1.Organization] add SetTableName("tenants") so tenant records target the renamed backing table.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • osac-project/fulfillment-service#588: Also modifies GenericDAOBuilder table-name resolution logic, directly overlapping with the SetTableName override added in this PR.
  • osac-project/fulfillment-service#593: Introduced ErrImmutable enforcement for organizations updates — the immutability tests retargeted to tenants in this PR are the direct continuation of that work.
  • osac-project/fulfillment-service#603: Added <table>_tenant_fk constraints referencing organizations(id); this PR updates database_tool.go and the migration to retarget those same constraints to tenants.

Suggested labels

lgtm

Suggested reviewers

  • trewest
  • adriengentil
  • eranco74

Poem

🏢 The orgs have packed their bags and gone,
Now tenants hold the table throne.
FKs rebound, triggers reborn,
SetTableName keeps the builders sworn.
What's in a name? Quite a bit of SQL! 🎉

🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Ai-Attribution ⚠️ Warning AI tool (Claude Code) mentioned in PR description but "Assisted-by" trailer missing from commit message (fb3eb58). Add "Assisted-by: Claude Code" trailer to the commit message to match PR description and follow Red Hat attribution conventions.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: renaming the organizations table to tenants, which is the primary scope of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No-Hardcoded-Secrets ✅ Passed No hardcoded secrets found. SetTableName methods accept plain table name strings ("tenants"). All changes are infrastructure/schema related with no API keys, tokens, passwords, or sensitive credent...
No-Weak-Crypto ✅ Passed PR contains no cryptographic code. Changes are limited to database table renaming and builder method additions for table name configuration.
No-Injection-Vectors ✅ Passed No new injection vectors introduced. SetTableName() is called only with hardcoded "tenants" literals; SQL concatenation patterns pre-date the PR; SQL migration uses format() with %I identifier quot...
Container-Privileges ✅ Passed PR modifies only Go source/test files and SQL migrations for database schema rename. No Kubernetes manifests, Docker configs, or container specifications present—check not applicable.
No-Sensitive-Data-In-Logs ✅ Passed PR introduces no logging that exposes passwords, tokens, API keys, PII, session IDs, hostnames, or customer data. All new code (SetTableName, resolveTableName) contains no logging. Existing logs on...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DakCrowder
DakCrowder requested a review from jhernand June 18, 2026 21:09

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for "down" files, we will never use them.

@omer-vishlitzky

Copy link
Copy Markdown
Contributor

/retest

Renames the organizations sql table to tenants and updates various references.  Also allows
for overriding the derived table name from .proto types to allow for exsting organizations
golang code to reference the tenants table.  This is a planned temporary change as the rename
progresses as a part of OSAC-1532.

Assisted-by: Claude Code
@DakCrowder
DakCrowder force-pushed the rename-organizations-table-to-tenants branch from 0412830 to fb3eb58 Compare June 22, 2026 13:44
@openshift-ci openshift-ci Bot removed the lgtm label Jun 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/database/migrations/58_rename_organizations_to_tenants_test.go`:
- Around line 24-33: The test cases in the It block are calling
tool.Migrate(ctx, 57) but should call tool.Migrate(ctx, 58) to properly run
migration 58 that renames the organizations table to tenants. Since the
BeforeEach already initializes the database at version 57, calling Migrate with
57 is a no-op and the actual migration never executes, causing the tenants table
insertion to fail. Update all instances of tool.Migrate(ctx, 57) to
tool.Migrate(ctx, 58) in all test cases within this test file (at lines 24, 36,
50, 64, and 84).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: e49c6c51-de98-4d3e-a871-dafe7c18c262

📥 Commits

Reviewing files that changed from the base of the PR and between 0412830 and fb3eb58.

📒 Files selected for processing (16)
  • internal/database/dao/dao_immutability_test.go
  • internal/database/dao/generic_dao.go
  • internal/database/dao/generic_dao_events_test.go
  • internal/database/dao/generic_dao_immutability_test.go
  • internal/database/dao/generic_dao_integrity_test.go
  • internal/database/database_tool.go
  • internal/database/migrations/58_rename_organizations_to_tenants.up.sql
  • internal/database/migrations/58_rename_organizations_to_tenants_test.go
  • internal/servers/generic_server.go
  • internal/servers/private_organizations_server.go
  • internal/servers/private_projects_server_test.go
  • internal/servers/private_public_ip_attachments_server_test.go
  • internal/servers/private_subnets_server_test.go
  • internal/servers/private_virtual_networks_server_test.go
  • internal/servers/projects_server_test.go
  • internal/servers/servers_tenancy_test.go

@DakCrowder
DakCrowder force-pushed the rename-organizations-table-to-tenants branch from fb3eb58 to a9883cf Compare June 22, 2026 13:54
@DakCrowder
DakCrowder requested a review from jhernand June 22, 2026 13:56
@openshift-ci openshift-ci Bot added the lgtm label Jun 22, 2026
@openshift-ci

openshift-ci Bot commented Jun 22, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DakCrowder, jhernand

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 44d236c into osac-project:main Jun 22, 2026
28 of 30 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants