Skip to content

NO-ISSUE: Add create_object_schema stored procedure#657

Open
jhernand wants to merge 1 commit into
osac-project:mainfrom
jhernand:add_create_object_schema_procedure
Open

NO-ISSUE: Add create_object_schema stored procedure#657
jhernand wants to merge 1 commit into
osac-project:mainfrom
jhernand:add_create_object_schema_procedure

Conversation

@jhernand

@jhernand jhernand commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a database migration (51) that creates a reusable create_object_schema stored procedure.
    The procedure encapsulates all the boilerplate DDL required when introducing a new object type:
    the object table, the archive table, the standard indexes, and the tenant foreign key. Future
    migrations can replace dozens of lines of repeated DDL with a single
    call create_object_schema('widgets').
  • Adds a migration test verifying the procedure is created.
  • Updates AGENTS.md with guidance directing contributors to use this procedure for new object
    types.

Test plan

  • ginkgo run internal/database/migrations passes (42/42 specs).
  • ginkgo run internal/database passes (63/63 specs).
  • Both binaries build cleanly (go build ./cmd/fulfillment-service, go build ./cmd/osac).

Summary by CodeRabbit

  • New Features

    • Added backend support for creating new database-backed object types, enabling consistent tables, archives, and indexes.
  • Documentation

    • Added guide on introducing new database-backed object types, including required schema artifacts and post-creation steps.
  • Tests

    • Added migration tests to verify the database infrastructure for creating new object types.

@openshift-ci-robot

Copy link
Copy Markdown

@jhernand: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

  • Adds a database migration (51) that creates a reusable create_object_schema stored procedure.
    The procedure encapsulates all the boilerplate DDL required when introducing a new object type:
    the object table, the archive table, the standard indexes, and the tenant foreign key. Future
    migrations can replace dozens of lines of repeated DDL with a single
    call create_object_schema('widgets').
  • Adds a migration test verifying the procedure is created.
  • Updates AGENTS.md with guidance directing contributors to use this procedure for new object
    types.

Test plan

  • ginkgo run internal/database/migrations passes (42/42 specs).
  • ginkgo run internal/database passes (63/63 specs).
  • Both binaries build cleanly (go build ./cmd/fulfillment-service, go build ./cmd/osac).

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 commented Jun 8, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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-ci openshift-ci Bot added the approved label Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 09cadceb-5bd3-48e4-bd70-e2651c37e201

📥 Commits

Reviewing files that changed from the base of the PR and between 525a488 and 8abd380.

📒 Files selected for processing (3)
  • AGENTS.md
  • internal/database/migrations/51_create_object_tables_procedure.up.sql
  • internal/database/migrations/51_create_object_tables_procedure_test.go

Walkthrough

Adds a PostgreSQL stored procedure create_object_schema(object_name) to generate standardized object and archived tables, indexes, and a tenant FK; includes a migration test verifying the procedure exists and an AGENTS.md section documenting how to use it in future migrations.

Changes

Object Schema Creation Procedure

Layer / File(s) Summary
Stored procedure implementation
internal/database/migrations/51_create_object_tables_procedure.up.sql
Defines create_object_schema(object_name) using dynamic SQL to create a primary object table with standard DAO columns and defaults, an archived_<object_name> table with adjusted schema (no finalizers, id non-PK, no timestamp defaults, added archival_timestamp), B-tree indexes on name/creator/tenant, a GIN index on labels, and a tenant FK to organizations(id).
Migration test
internal/database/migrations/51_create_object_tables_procedure_test.go
Adds a Ginkgo/Gomega test that runs migration 51 and asserts exactly one public procedure named create_object_schema exists by querying the catalog.
Developer guidance
AGENTS.md
New "Introducing New Object Types" section instructs maintainers to call create_object_schema when adding new object kinds and to append any resource-specific schema additions (extra indexes, helper tables) after the procedure call.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

approved

Suggested reviewers

  • tzumainn
  • omer-vishlitzky

"A migration sings a single call,
tables rise and indexes fall,
archives timestamp every deed,
one proc plants the schema seed.
🎉"

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a create_object_schema stored procedure to the codebase.
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, API keys, tokens, passwords, or credentials detected in the PR's three modified files (AGENTS.md, SQL migration, and test file).
No-Weak-Crypto ✅ Passed PR contains no cryptographic code: no weak algorithms, custom crypto implementations, or secret comparisons. Changes are database schema setup and testing only.
No-Injection-Vectors ✅ Passed PR uses PostgreSQL format() with %I placeholder for safe identifier handling, hardcoded SQL literals in tests, and no dangerous patterns (string concatenation, eval, shell=True, yaml.load, etc.).
Container-Privileges ✅ Passed PR contains only database migration SQL, Go tests, and documentation - no container/K8s manifests present to assess for privileged settings.
No-Sensitive-Data-In-Logs ✅ Passed No logging statements found that expose sensitive data. All database operations use parameterized queries with proper identifier quoting (%I).
Ai-Attribution ✅ Passed AI tool (Cursor) was used and properly attributed with "Assisted-by: Cursor" trailer. No improper Co-Authored-By usage detected. Red Hat attribution is correctly applied.

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

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

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

Add a database migration that creates a reusable `create_object_schema`
stored procedure. It encapsulates the boilerplate DDL that every new
object type requires: the object table with all standard DAO columns,
the corresponding archive table, the four standard indexes on `name`,
`creator`, `tenant`, and `labels`, and the tenant foreign key
constraint referencing the `organizations` table.

Future migrations that introduce a new object type can call the
procedure instead of repeating the DDL manually:

```sql
call create_object_schema('widgets');
```

The AGENTS.md file is updated with guidance directing contributors to
use this procedure when introducing new object types.

Assisted-by: Cursor
Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
@jhernand jhernand force-pushed the add_create_object_schema_procedure branch from 525a488 to 8abd380 Compare June 8, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants