Skip to content

Refactor seedTemplateTablesService for better separation of responsibilities#1720

Merged
cezudas merged 5 commits intomainfrom
cezudas/OPS-3009-refactor-seed-tables-for-templates
Dec 3, 2025
Merged

Refactor seedTemplateTablesService for better separation of responsibilities#1720
cezudas merged 5 commits intomainfrom
cezudas/OPS-3009-refactor-seed-tables-for-templates

Conversation

@cezudas
Copy link
Copy Markdown
Contributor

@cezudas cezudas commented Dec 3, 2025

Part of OPS-3009.

@linear
Copy link
Copy Markdown

linear Bot commented Dec 3, 2025

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 3, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cezudas/OPS-3009-refactor-seed-tables-for-templates

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the template table seeding logic by extracting table creation logic into reusable helper functions and adds a new public method for seeding template tables for a given database.

  • Extracted base template table creation logic into seedBaseTemplateTables helper function
  • Extracted additional template table creation logic into seedAdditionalTemplateTables helper function
  • Added new seedTemplateTablesForDatabase method that seeds both base and additional template tables for a specified database

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

Extracted template table seeding logic into reusable helper functions seedBaseTemplateTables and seedAdditionalTemplateTables, then introduced new public method seedTemplateTablesForDatabase to enable seeding with provided database credentials.

Key changes:

  • Refactored createBaseTemplateTables to use new seedBaseTemplateTables helper
  • Created seedAdditionalTemplateTables helper for additional table creation
  • Added seedTemplateTablesForDatabase method accepting databaseId and credentials as parameters

Critical issue found:

  • Parameter order inconsistency in seedAdditionalTemplateTables will cause runtime errors when calling table creation functions

Confidence Score: 1/5

  • This PR contains a critical parameter ordering bug that will cause runtime failures
  • The refactoring introduces inconsistent parameter ordering in seedAdditionalTemplateTables (lines 48-51). Multiple table creation functions expect different parameter orders: createOpportunitiesTable(token, databaseId) vs createAggregatedCostsTable(databaseId, token). This will cause authentication and database lookup failures at runtime.
  • The parameter ordering bug in seedAdditionalTemplateTables function at seed-tables-for-templates.ts:48-51 must be fixed before merging

Important Files Changed

File Analysis

Filename Score Overview
packages/server/api/src/app/openops-tables/template-tables/seed-tables-for-templates.ts 2/5 Refactored template table seeding into reusable helper functions; critical parameter ordering bug found in seedAdditionalTemplateTables

Sequence Diagram

sequenceDiagram
    participant Client
    participant Service as seedTemplateTablesService
    participant AuthFunc as authenticateAdmin
    participant ProjectFunc as getProjectDatabaseId
    participant BaseFunc as seedBaseTables
    participant AdditionalFunc as seedAdditionalTables
    participant TableAPIs as Table Creation APIs

    Note over Client,TableAPIs: New Method: seedTemplateTablesForDatabase

    Client->>Service: seedTemplateTablesForDatabase(dbId, credentials)
    Service->>BaseFunc: seedBaseTemplateTables(dbId, credentials)
    BaseFunc->>TableAPIs: createBusinessUnitsTable
    TableAPIs-->>BaseFunc: buTable
    BaseFunc->>TableAPIs: createTagOwnerMappingTable
    BaseFunc->>TableAPIs: createIdleEbsVolumesToDeleteTable
    BaseFunc->>TableAPIs: createResourceBuTagAssignmentTable
    BaseFunc-->>Service: Done
    Service->>AdditionalFunc: seedAdditionalTemplateTables(dbId, credentials)
    AdditionalFunc->>TableAPIs: createOpportunitiesTable
    AdditionalFunc->>TableAPIs: createAggregatedCostsTable
    AdditionalFunc->>TableAPIs: createKnownCostTypesByApplicationTable
    AdditionalFunc->>TableAPIs: createAutoInstancesShutdownTable
    AdditionalFunc-->>Service: Done
    Service-->>Client: Complete

    Note over Client,TableAPIs: Refactored: createBaseTemplateTables

    Client->>Service: createBaseTemplateTables()
    Service->>AuthFunc: authenticate()
    AuthFunc-->>Service: credentials
    Service->>ProjectFunc: getDatabaseId()
    ProjectFunc-->>Service: dbId
    Service->>BaseFunc: seedBaseTemplateTables(dbId, credentials)
    BaseFunc-->>Service: Done
    Service-->>Client: Complete
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@cezudas cezudas changed the title Create new seed template tables helper Refactor seedTemplateTablesService for better separation of responsibilities Dec 3, 2025
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 3, 2025

throw new Error(`No project found for user: ${email}`);
}

return project;
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.

doesnt it need to be return project.tablesDatabaseId?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this return stmt is for getAdminUserProject helper.
We used to have getProjectTablesDatabaseId helper (in packages/server/api/src/app/openops-tables/template-tables/seed-tables-for-templates.ts).

@cezudas cezudas merged commit 804eb47 into main Dec 3, 2025
24 checks passed
@cezudas cezudas deleted the cezudas/OPS-3009-refactor-seed-tables-for-templates branch December 3, 2025 13:45
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.

3 participants