Repository navigation
feat(database): add new advanced filter group by column to features - #3470
Conversation
📝 WalkthroughWalkthroughRenames the ent/db feature package to the alias dbfeature across the codebase, adds a new nullable JSON column advanced_meter_group_by_filters to Feature (schema, ent models, builders, predicates, queries), updates productcatalog adapter logic to set/use this field, and includes SQL migrations with a test to backfill data. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (32)
openmeter/ent/db/addonratecard.go(2 hunks)openmeter/ent/db/addonratecard/addonratecard.go(1 hunks)openmeter/ent/db/addonratecard_create.go(2 hunks)openmeter/ent/db/addonratecard_query.go(3 hunks)openmeter/ent/db/addonratecard_update.go(5 hunks)openmeter/ent/db/client.go(10 hunks)openmeter/ent/db/ent.go(2 hunks)openmeter/ent/db/entitlement.go(2 hunks)openmeter/ent/db/entitlement/entitlement.go(1 hunks)openmeter/ent/db/entitlement_create.go(2 hunks)openmeter/ent/db/entitlement_query.go(3 hunks)openmeter/ent/db/feature.go(5 hunks)openmeter/ent/db/feature/feature.go(3 hunks)openmeter/ent/db/feature/where.go(2 hunks)openmeter/ent/db/feature_create.go(13 hunks)openmeter/ent/db/feature_delete.go(3 hunks)openmeter/ent/db/feature_query.go(21 hunks)openmeter/ent/db/feature_update.go(27 hunks)openmeter/ent/db/migrate/schema.go(1 hunks)openmeter/ent/db/mutation.go(22 hunks)openmeter/ent/db/planratecard.go(2 hunks)openmeter/ent/db/planratecard/planratecard.go(1 hunks)openmeter/ent/db/planratecard_create.go(2 hunks)openmeter/ent/db/planratecard_query.go(3 hunks)openmeter/ent/db/planratecard_update.go(5 hunks)openmeter/ent/db/predicate/predicate.go(1 hunks)openmeter/ent/db/runtime.go(2 hunks)openmeter/ent/db/setorclear.go(2 hunks)openmeter/ent/schema/feature.go(2 hunks)openmeter/productcatalog/adapter/feature.go(2 hunks)tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.down.sql(1 hunks)tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (24)
openmeter/ent/db/planratecard_update.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/productcatalog/adapter/feature.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMeterGroupByFiltersToMapString(102-116)
openmeter/ent/db/entitlement.go (2)
openmeter/ent/db/ent.go (1)
NotFoundError(285-287)openmeter/ent/db/feature/feature.go (1)
Label(14-14)
openmeter/ent/db/addonratecard.go (2)
openmeter/ent/db/ent.go (1)
NotFoundError(285-287)openmeter/ent/db/feature/feature.go (1)
Label(14-14)
openmeter/ent/db/setorclear.go (2)
openmeter/ent/db/feature_update.go (2)
FeatureUpdate(23-27)FeatureUpdateOne(489-494)openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/ent/db/feature_create.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (26)
DefaultCreatedAt(98-98)DefaultUpdatedAt(100-100)DefaultID(110-110)NamespaceValidator(104-104)NameValidator(106-106)KeyValidator(108-108)Table(46-46)FieldID(16-16)FieldCreatedAt(18-18)FieldUpdatedAt(20-20)FieldDeletedAt(22-22)FieldMetadata(24-24)FieldNamespace(26-26)FieldName(28-28)FieldKey(30-30)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)EntitlementTable(48-48)Columns(71-84)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)
openmeter/ent/db/planratecard_create.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/ent/db/feature_delete.go (2)
openmeter/ent/db/feature/feature.go (3)
Table(46-46)FieldID(16-16)Label(14-14)openmeter/ent/db/ent.go (1)
NotFoundError(285-287)
openmeter/ent/db/planratecard_query.go (2)
openmeter/ent/db/feature/feature.go (2)
Table(46-46)FieldID(16-16)openmeter/ent/db/feature/where.go (1)
IDIn(29-31)
openmeter/ent/db/addonratecard_query.go (2)
openmeter/ent/db/feature/feature.go (2)
Table(46-46)FieldID(16-16)openmeter/ent/db/feature/where.go (1)
IDIn(29-31)
openmeter/ent/db/ent.go (1)
openmeter/ent/db/feature/feature.go (2)
Table(46-46)ValidColumn(87-94)
openmeter/ent/db/feature_query.go (2)
openmeter/ent/db/feature/feature.go (12)
OrderOption(114-114)Table(46-46)FieldID(16-16)EntitlementTable(48-48)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)Label(14-14)ValidColumn(87-94)Columns(71-84)openmeter/ent/db/ent.go (2)
NotFoundError(285-287)NotSingularError(312-314)
openmeter/ent/db/addonratecard_create.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/ent/db/addonratecard_update.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/ent/db/mutation.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (7)
FieldMetadata(24-24)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)FieldName(28-28)FieldKey(30-30)
openmeter/ent/db/client.go (3)
openmeter/ent/db/feature/feature.go (8)
Table(46-46)FieldID(16-16)EntitlementTable(48-48)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)openmeter/ent/db/feature.go (2)
Feature(18-48)Feature(91-106)openmeter/ent/db/feature/where.go (1)
ID(14-16)
openmeter/ent/db/feature/where.go (3)
openmeter/ent/db/feature.go (2)
Feature(18-48)Feature(91-106)openmeter/ent/schema/feature.go (5)
Feature(14-16)Feature(18-24)Feature(26-36)Feature(38-47)Feature(49-61)openmeter/ent/db/feature/feature.go (1)
FieldAdvancedMeterGroupByFilters(36-36)
openmeter/ent/db/feature_update.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (15)
Table(46-46)Columns(71-84)FieldID(16-16)FieldUpdatedAt(20-20)FieldDeletedAt(22-22)FieldMetadata(24-24)FieldName(28-28)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)EntitlementTable(48-48)RatecardTable(55-55)AddonRatecardTable(62-62)Label(14-14)
openmeter/ent/db/entitlement_create.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/ent/db/planratecard.go (2)
openmeter/ent/db/ent.go (1)
NotFoundError(285-287)openmeter/ent/db/feature/feature.go (1)
Label(14-14)
openmeter/ent/schema/feature.go (1)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/ent/db/entitlement_query.go (2)
openmeter/ent/db/feature/feature.go (2)
Table(46-46)FieldID(16-16)openmeter/ent/db/feature/where.go (1)
IDIn(29-31)
openmeter/ent/db/feature.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (5)
FieldMetadata(24-24)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldID(16-16)FieldArchivedAt(38-38)
openmeter/ent/db/runtime.go (3)
openmeter/ent/db/feature.go (2)
Feature(18-48)Feature(91-106)openmeter/ent/schema/feature.go (5)
Feature(14-16)Feature(18-24)Feature(26-36)Feature(38-47)Feature(49-61)openmeter/ent/db/feature/feature.go (4)
DefaultUpdatedAt(100-100)UpdateDefaultUpdatedAt(102-102)NameValidator(106-106)KeyValidator(108-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Migration Checks
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Build
- GitHub Check: Lint
- GitHub Check: Release note label
- GitHub Check: Analyze (go)
🔇 Additional comments (10)
openmeter/ent/db/entitlement/entitlement.go (1)
115-115: LGTM: Documentation updated to reflect package rename.The comment correctly reflects the rename from
featuretodbfeaturepackage, consistent with the broader refactoring in this PR. The database table name"features"on line 116 appropriately remains unchanged.openmeter/ent/db/addonratecard_update.go (2)
16-16: LGTM! Package alias refactoring is consistent.The import alias change from
featuretodbfeatureand corresponding updates to edge target ID specifications are systematically applied for theAddonRateCardUpdatebuilder.Also applies to: 464-464, 477-477
964-964: LGTM! UpdateOne builder changes match the Update builder.Edge target specifications in
AddonRateCardUpdateOnecorrectly use thedbfeature.FieldIDalias, maintaining consistency with theAddonRateCardUpdatebuilder changes.Also applies to: 977-977
openmeter/ent/db/feature_query.go (1)
18-18: LGTM! Comprehensive and consistent package alias refactoring.All references to the feature package have been systematically updated to use the
dbfeaturealias throughout the query builder, including:
- Order types and method signatures
- Edge specifications for entitlement, ratecard, and addon_ratecard
- Error construction (NotFoundError, NotSingularError labels)
- Field validation and selection
- Query specification and SQL construction
The refactoring is complete and maintains consistency across all query operations.
Also applies to: 27-27, 65-65, 82-84, 104-106, 126-128, 144-144, 166-166, 193-195, 220-222, 261-261, 325-325, 388-388, 408-408, 430-430, 513-513, 543-543, 576-576, 609-609, 618-620, 650-653
openmeter/ent/db/feature_create.go (3)
17-19: LGTM! Dual import strategy enables new field support.The use of both
dbfeature(for ent constants) andfeature(for domain types) imports allows proper integration of the newadvanced_meter_group_by_filtersfield. TheSetAdvancedMeterGroupByFiltersmethod follows the established pattern for field setters.Also applies to: 116-120
231-239: LGTM! Field integration in createSpec is correct.The create specification properly integrates the new
advanced_meter_group_by_filtersfield (lines 348-351) with JSON field type, and all table/field/column references correctly use thedbfeaturealias for defaults, validators, and edge specifications.Also applies to: 256-272, 305-305, 313-351, 360-393
458-550: LGTM! Complete upsert integration for the new field.The
advanced_meter_group_by_filtersfield is fully integrated across all upsert paths:
FeatureUpsert: Set, Update, and Clear operations (lines 534-550)FeatureUpsertOne: Set, Update, and Clear operations (lines 721-740)FeatureUpsertBulk: Set, Update, and Clear operations (lines 1081-1100)All operations follow the established pattern and correctly use
dbfeaturefor field constants.Also applies to: 577-598, 721-740, 935-957, 1081-1100
openmeter/ent/db/feature_update.go (3)
16-19: LGTM! New field methods added to FeatureUpdate.The dual import strategy and new
SetAdvancedMeterGroupByFiltersandClearAdvancedMeterGroupByFiltersmethods follow the established pattern for field updates in theFeatureUpdatebuilder.Also applies to: 99-109
275-283: LGTM! SQL update logic correctly handles the new field.The
sqlSaveimplementation forFeatureUpdateproperly integrates the new field with both Set (line 330) and Clear (line 333) operations. All field and edge specifications consistently usedbfeaturereferences, and error construction usesdbfeature.Label.Also applies to: 294-339, 345-474, 478-478
560-570: LGTM! FeatureUpdateOne mirrors FeatureUpdate changes.The
FeatureUpdateOnebuilder has complete support for the new field (lines 560-570, 820-824) and all references consistently usedbfeaturefor field constants, validators, defaults, and edge specifications. The implementation maintains parity with theFeatureUpdatebuilder.Also applies to: 749-757, 768-830, 836-965, 972-972
| func (m *FeatureMutation) SetAdvancedMeterGroupByFilters(fgbf feature.MeterGroupByFilters) { | ||
| m.advanced_meter_group_by_filters = &fgbf | ||
| } |
There was a problem hiding this comment.
Remove stale clear flag when re-setting the field
SetAdvancedMeterGroupByFilters never removes dbfeature.FieldAdvancedMeterGroupByFilters from clearedFields. After calling ClearAdvancedMeterGroupByFilters, any later SetAdvanced... leaves the field flagged as cleared and the end builder will still write NULL, dropping the freshly assigned value. Please mirror the pattern used by the other setters:
func (m *FeatureMutation) SetAdvancedMeterGroupByFilters(fgbf feature.MeterGroupByFilters) {
m.advanced_meter_group_by_filters = &fgbf
+ delete(m.clearedFields, dbfeature.FieldAdvancedMeterGroupByFilters)
}🤖 Prompt for AI Agents
In openmeter/ent/db/mutation.go around lines 34673-34675,
SetAdvancedMeterGroupByFilters currently sets m.advanced_meter_group_by_filters
but does not clear the stale clear flag; update the setter to also delete
m.clearedFields[dbfeature.FieldAdvancedMeterGroupByFilters] (or call the
equivalent remove on the clearedFields collection) before assigning the pointer
so it mirrors other setters and prevents the field from being written as NULL
after a prior ClearAdvancedMeterGroupByFilters call.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tools/migrate/feature_meter_group_by_test.go (2)
24-218: Consider adding down migration and idempotency verification.The test currently only verifies the up migration. For comprehensive migration testing, consider adding:
Down migration verification: Test that rolling back the migration properly removes the
advanced_meter_group_by_filterscolumn and preserves the originalmeter_group_by_filtersdata.Idempotency check: Verify that running the up migration twice produces the same result without errors or data corruption.
Example structure for down migration test:
{ // TEST SCENARIO 3: Verify down migration // After rolling back, advanced_meter_group_by_filters column should be removed // and meter_group_by_filters should remain unchanged version: 20251006141236, direction: directionDown, action: func(t *testing.T, db *sql.DB) { // Verify column no longer exists var columnExists bool err := db.QueryRow(` SELECT EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_name = 'features' AND column_name = 'advanced_meter_group_by_filters' ) `).Scan(&columnExists) require.NoError(t, err) require.False(t, columnExists, "advanced_meter_group_by_filters column should not exist after rollback") // Verify original data is preserved var originalFilters sql.NullString err = db.QueryRow(` SELECT meter_group_by_filters FROM features WHERE id = $1 `, singleFeatureId.String()).Scan(&originalFilters) require.NoError(t, err) require.JSONEq(t, `{"region":"us-east-1"}`, originalFilters.String) }, },
203-215: Column existence check is redundant but harmless.The column existence check at lines 203-215 is technically redundant since the previous
SELECTqueries (lines 154-201) would have already failed if the column didn't exist. However, having an explicit check improves test clarity and provides a more specific error message if the migration fails to create the column.If you prefer to keep the test concise, you could remove this check, as the earlier queries already validate the column's presence indirectly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
tools/migrate/feature_meter_group_by_test.go(1 hunks)tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql
🔇 Additional comments (1)
tools/migrate/feature_meter_group_by_test.go (1)
11-219: Well-structured migration test with correct verification logic.The test properly validates the migration's data transformation from simple key-value filters to advanced filters with
$eqoperators. The use of parameterized queries, NULL handling withsql.NullString, and JSON comparison withrequire.JSONEqare all appropriate.
bcbf8a1 to
3d724b6
Compare
3d724b6 to
9a24ac9
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (2)
tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql (1)
17-19: Acknowledge the performance concern and test requirement.The WHERE clause correctly handles edge cases (SQL NULL, JSON null, and type checking). However, as noted in the previous review, this UPDATE will perform a full table scan and could timeout on large tables.
As suggested in the previous review:
- Add a test to verify the migration behavior
- Consider making this a manual deployment step if the table is large
- Monitor execution time in staging before running in production
openmeter/ent/db/mutation.go (1)
34673-34675: Remove stale clear flag when setting the field.This is the same issue flagged in the previous review:
SetAdvancedMeterGroupByFiltersdoes not remove the field fromclearedFields. IfClearAdvancedMeterGroupByFiltersis called first, thenSetAdvancedMeterGroupByFiltersis called later, the field will remain marked as cleared and the builder will writeNULL, discarding the newly assigned value.Apply this diff to fix:
func (m *FeatureMutation) SetAdvancedMeterGroupByFilters(fgbf feature.MeterGroupByFilters) { m.advanced_meter_group_by_filters = &fgbf + delete(m.clearedFields, dbfeature.FieldAdvancedMeterGroupByFilters) }
🧹 Nitpick comments (4)
tools/migrate/feature_advanced_meter_group_by_filters_test.go (2)
172-176: Prefer JSONEq for JSON comparisonsUse JSONEq instead of string equality for "{}", avoiding formatting issues from driver/DB.
- require.Equal(t, "{}", originalFilters.String, "Original filters should remain empty object") + require.JSONEq(t, "{}", originalFilters.String, "Original filters should remain empty object") - require.True(t, advancedFilters.Valid, "Advanced filters should not be NULL") - require.Equal(t, "{}", advancedFilters.String, "Advanced filters should be empty object") + require.True(t, advancedFilters.Valid, "Advanced filters should not be NULL") + require.JSONEq(t, "{}", advancedFilters.String, "Advanced filters should be empty object")
206-214: Scope the column existence check to current schemaAdd table_schema filter to avoid false positives if multiple schemas exist.
- SELECT EXISTS ( - SELECT 1 - FROM information_schema.columns - WHERE table_name = 'features' - AND column_name = 'advanced_meter_group_by_filters' - ) + SELECT EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = current_schema() + AND table_name = 'features' + AND column_name = 'advanced_meter_group_by_filters' + )openmeter/productcatalog/adapter/feature.go (2)
48-52: Set advanced always when provided; set legacy only if convertiblelen(...) > 0 skips explicit empty {}. Also, only set the legacy map when conversion succeeds.
- if len(feat.MeterGroupByFilters) > 0 { - query = query. - SetAdvancedMeterGroupByFilters(feat.MeterGroupByFilters). - SetMeterGroupByFilters(feature.ConvertMeterGroupByFiltersToMapString(feat.MeterGroupByFilters)) - } + if feat.MeterGroupByFilters != nil { + query = query.SetAdvancedMeterGroupByFilters(feat.MeterGroupByFilters) + if m := feature.ConvertMeterGroupByFiltersToMapString(feat.MeterGroupByFilters); m != nil { + query = query.SetMeterGroupByFilters(m) + } + }
258-263: Detect presence by nil, not lengthPrefer advanced filters whenever present, even if empty {}; fallback to legacy only if advanced is nil.
- // Use advanced meter group by filters if available - if len(entity.AdvancedMeterGroupByFilters) > 0 { + // Use advanced meter group by filters if available (even if empty) + if entity.AdvancedMeterGroupByFilters != nil { f.MeterGroupByFilters = entity.AdvancedMeterGroupByFilters - } else if len(entity.MeterGroupByFilters) > 0 { + } else if entity.MeterGroupByFilters != nil { f.MeterGroupByFilters = feature.ConvertMapStringToMeterGroupByFilters(entity.MeterGroupByFilters) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (33)
openmeter/ent/db/addonratecard.go(2 hunks)openmeter/ent/db/addonratecard/addonratecard.go(1 hunks)openmeter/ent/db/addonratecard_create.go(2 hunks)openmeter/ent/db/addonratecard_query.go(3 hunks)openmeter/ent/db/addonratecard_update.go(5 hunks)openmeter/ent/db/client.go(10 hunks)openmeter/ent/db/ent.go(2 hunks)openmeter/ent/db/entitlement.go(2 hunks)openmeter/ent/db/entitlement/entitlement.go(1 hunks)openmeter/ent/db/entitlement_create.go(2 hunks)openmeter/ent/db/entitlement_query.go(3 hunks)openmeter/ent/db/feature.go(5 hunks)openmeter/ent/db/feature/feature.go(3 hunks)openmeter/ent/db/feature/where.go(2 hunks)openmeter/ent/db/feature_create.go(13 hunks)openmeter/ent/db/feature_delete.go(3 hunks)openmeter/ent/db/feature_query.go(21 hunks)openmeter/ent/db/feature_update.go(27 hunks)openmeter/ent/db/migrate/schema.go(1 hunks)openmeter/ent/db/mutation.go(22 hunks)openmeter/ent/db/planratecard.go(2 hunks)openmeter/ent/db/planratecard/planratecard.go(1 hunks)openmeter/ent/db/planratecard_create.go(2 hunks)openmeter/ent/db/planratecard_query.go(3 hunks)openmeter/ent/db/planratecard_update.go(5 hunks)openmeter/ent/db/predicate/predicate.go(1 hunks)openmeter/ent/db/runtime.go(2 hunks)openmeter/ent/db/setorclear.go(2 hunks)openmeter/ent/schema/feature.go(2 hunks)openmeter/productcatalog/adapter/feature.go(2 hunks)tools/migrate/feature_advanced_meter_group_by_filters_test.go(1 hunks)tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.down.sql(1 hunks)tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (17)
- openmeter/ent/db/entitlement_query.go
- tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.down.sql
- openmeter/ent/db/planratecard.go
- openmeter/ent/db/entitlement.go
- openmeter/ent/db/feature/where.go
- openmeter/ent/db/migrate/schema.go
- openmeter/ent/db/entitlement_create.go
- openmeter/ent/db/addonratecard_create.go
- openmeter/ent/db/addonratecard_query.go
- openmeter/ent/db/addonratecard_update.go
- openmeter/ent/db/planratecard_create.go
- openmeter/ent/db/addonratecard.go
- openmeter/ent/db/runtime.go
- openmeter/ent/db/predicate/predicate.go
- openmeter/ent/db/entitlement/entitlement.go
- openmeter/ent/db/ent.go
- openmeter/ent/db/addonratecard/addonratecard.go
🧰 Additional context used
🧬 Code graph analysis (12)
openmeter/ent/db/planratecard_update.go (1)
openmeter/ent/db/feature/feature.go (1)
FieldID(16-16)
openmeter/ent/db/feature.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (12)
FieldMetadata(24-24)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldID(16-16)FieldNamespace(26-26)FieldName(28-28)FieldKey(30-30)FieldMeterSlug(32-32)FieldCreatedAt(18-18)FieldUpdatedAt(20-20)FieldDeletedAt(22-22)FieldArchivedAt(38-38)
openmeter/ent/db/feature_delete.go (2)
openmeter/ent/db/feature/feature.go (3)
Table(46-46)FieldID(16-16)Label(14-14)openmeter/ent/db/ent.go (1)
NotFoundError(285-287)
openmeter/ent/db/planratecard_query.go (2)
openmeter/ent/db/feature/feature.go (2)
Table(46-46)FieldID(16-16)openmeter/ent/db/feature/where.go (1)
IDIn(29-31)
openmeter/ent/db/feature_query.go (2)
openmeter/ent/db/feature/feature.go (12)
OrderOption(114-114)Table(46-46)FieldID(16-16)EntitlementTable(48-48)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)Label(14-14)ValidColumn(87-94)Columns(71-84)openmeter/ent/db/ent.go (2)
NotFoundError(285-287)NotSingularError(312-314)
openmeter/productcatalog/adapter/feature.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMeterGroupByFiltersToMapString(102-116)
openmeter/ent/schema/feature.go (1)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/ent/db/feature_create.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (20)
DefaultCreatedAt(98-98)DefaultUpdatedAt(100-100)DefaultID(110-110)NamespaceValidator(104-104)NameValidator(106-106)KeyValidator(108-108)Table(46-46)FieldID(16-16)FieldCreatedAt(18-18)FieldUpdatedAt(20-20)FieldDeletedAt(22-22)FieldMetadata(24-24)FieldNamespace(26-26)FieldName(28-28)FieldKey(30-30)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)Columns(71-84)
openmeter/ent/db/mutation.go (3)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/schema/feature.go (5)
Feature(14-16)Feature(18-24)Feature(26-36)Feature(38-47)Feature(49-61)openmeter/ent/db/feature/feature.go (7)
FieldMetadata(24-24)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)FieldName(28-28)FieldKey(30-30)
openmeter/ent/db/client.go (5)
openmeter/ent/db/addonratecard/addonratecard.go (2)
Table(59-59)FieldID(19-19)openmeter/ent/db/entitlement/entitlement.go (2)
Table(83-83)FieldID(19-19)openmeter/ent/db/feature/feature.go (8)
Table(46-46)FieldID(16-16)EntitlementTable(48-48)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)openmeter/ent/db/planratecard/planratecard.go (2)
Table(59-59)FieldID(19-19)openmeter/ent/db/feature/where.go (1)
ID(14-16)
openmeter/ent/db/setorclear.go (2)
openmeter/ent/db/feature_update.go (2)
FeatureUpdate(23-27)FeatureUpdateOne(489-494)openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/ent/db/feature_update.go (3)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)openmeter/ent/db/feature/feature.go (21)
UpdateDefaultUpdatedAt(102-102)NameValidator(106-106)Table(46-46)Columns(71-84)FieldID(16-16)FieldUpdatedAt(20-20)FieldDeletedAt(22-22)FieldMetadata(24-24)FieldName(28-28)FieldMeterSlug(32-32)FieldMeterGroupByFilters(34-34)FieldAdvancedMeterGroupByFilters(36-36)FieldArchivedAt(38-38)EntitlementTable(48-48)EntitlementColumn(53-53)RatecardTable(55-55)RatecardColumn(60-60)AddonRatecardTable(62-62)AddonRatecardColumn(67-67)Label(14-14)ValidColumn(87-94)openmeter/ent/db/ent.go (1)
NotFoundError(285-287)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: E2E
- GitHub Check: Quickstart
- GitHub Check: Lint
- GitHub Check: Migration Checks
- GitHub Check: Test
- GitHub Check: Build
- GitHub Check: Code Generators
- GitHub Check: Analyze (go)
🔇 Additional comments (19)
openmeter/ent/schema/feature.go (1)
33-33: Clarify the relationship between meter_group_by_filters and advanced_meter_group_by_filters.Both fields coexist in the schema. Consider documenting:
- Whether one supersedes the other
- Migration/deprecation strategy for the old field
- If validation is needed for the new field (several other fields have validators)
tools/migrate/migrations/20251006141236_feature-advanced-meter-group-by-filters.up.sql (2)
1-2: LGTM!Adding the nullable column is a safe, non-blocking operation.
6-16: Verify $eq-only transformationMigration wraps all meter_group_by_filters entries in {"$eq": value}. Manually confirm that no existing filters rely on other operators or non-text values that would be lost.
openmeter/ent/db/setorclear.go (1)
2173-2186: Advanced SetOrClear helpers look correctNil-clears and non-nil-sets mirror existing pattern. Type usage aligns with feature.MeterGroupByFilters.
openmeter/ent/db/feature_update.go (2)
16-20: Alias migration to dbfeature looks consistentImports/identifiers updated coherently across the file.
Please re-run ent code generation to ensure no local manual edits drift from templates and all new methods are covered by generated code.
99-109: Advanced filters field wired end-to-end — LGTMSet/Clear methods and SQL spec handling for advanced_meter_group_by_filters are correct in both Update and UpdateOne.
Also applies to: 329-334, 560-570, 820-825
openmeter/ent/db/feature_query.go (1)
65-69: dbfeature alias refactor and query wiring look goodOrder, predicates, columns, and labels are consistently updated; edge loaders reference correct FK columns.
Also applies to: 82-86, 104-108, 126-129, 144-146, 166-167, 193-196, 220-223, 261-265, 325-335, 381-384, 404-411, 431-434, 609-646, 649-655
openmeter/ent/db/feature_create.go (5)
1-20: LGTM: Import aliasing is clear and prevents naming conflicts.The introduction of the
dbfeaturealias foropenmeter/ent/db/featureand the unaliased import ofopenmeter/productcatalog/featureprovides clear disambiguation between the database schema package and the domain model package. This pattern allows the code to reference database constants viadbfeature.*while using the domain typefeature.MeterGroupByFiltersin the public API.
116-120: LGTM: New field setter follows ent patterns correctly.The
SetAdvancedMeterGroupByFiltersmethod correctly uses the domain typefeature.MeterGroupByFiltersfrom the productcatalog package and delegates to the mutation object, following the same pattern as other field setters in this builder.
348-351: LGTM: Field creation logic is consistent with other JSON fields.The handling of
AdvancedMeterGroupByFiltersincreateSpeccorrectly sets the field value when present in the mutation, using the appropriate field constant and type (TypeJSON). This matches the pattern used for the existingMeterGroupByFiltersfield.
534-550: LGTM: Upsert methods are complete and consistent.The upsert methods for
AdvancedMeterGroupByFiltersacrossFeatureUpsert,FeatureUpsertOne, andFeatureUpsertBulkprovide complete functionality:
- Set: assigns a new value
- Update: uses the value from the create operation
- Clear: sets the field to NULL
This pattern is consistent with other optional JSON fields in the builder.
Also applies to: 721-740, 1081-1100
231-403: LGTM: Comprehensive refactoring to dbfeature alias.All references to database schema constants (DefaultCreatedAt, DefaultUpdatedAt, DefaultID, validators, field names, table names, and column names) have been correctly updated to use the
dbfeaturealias. This change is consistent throughout the file and maintains the same semantics as before while improving clarity.openmeter/ent/db/mutation.go (7)
44-44: LGTM! Import structure is correct.The dual import approach is appropriate:
dbfeaturealias for schema constantsfeaturepackage for the domain typeMeterGroupByFiltersThis follows the established pattern for other schema packages in the file.
Also applies to: 66-66
34175-34175: LGTM! Field correctly added to mutation struct.The new field uses the proper domain type
feature.MeterGroupByFiltersas a pointer, allowing nil state for this optional field.
34677-34719: LGTM! Getter, clear, and reset methods are correctly implemented.The methods follow the established patterns:
- Getter returns value with exists flag
- OldValue retrieval validates operation type and fetches from database
- Clear correctly marks field as cleared
- Reset properly removes the clear flag
34402-34402: LGTM! Constant references correctly updated.All field constant references have been properly updated from
feature.Field*todbfeature.Field*to reflect the new import alias.Also applies to: 34407-34407, 34414-34414, 34451-34451, 34456-34456, 34463-34463, 34608-34608, 34613-34613, 34620-34620, 34657-34657, 34662-34662, 34669-34669, 34755-34755, 34760-34760, 34767-34767
34966-35001: LGTM! Fields() method correctly updated.The field count has been properly incremented to 11, and the new
advanced_meter_group_by_filtersfield is correctly included in the list with the appropriate constant reference.
35026-35027: LGTM! All switch cases correctly updated.The new field has been properly integrated into all mutation methods:
Field()returns the valueOldField()retrieves the old valueSetField()validates type and calls setterClearedFields()checks cleared statusClearField()clears the fieldResetField()resets the fieldAll use the correct constant references and type assertions.
Also applies to: 35057-35058, 35133-35139, 35189-35190, 35221-35223, 35262-35264
35276-35276: LGTM! Edge constant references correctly updated.All edge constant references have been properly updated from
feature.Edge*todbfeature.Edge*across all edge-related methods, maintaining consistency with the new import structure.Also applies to: 35279-35279, 35282-35282, 35291-35291, 35297-35297, 35303-35303, 35317-35317, 35320-35320, 35323-35323, 35332-35332, 35338-35338, 35344-35344, 35358-35358, 35361-35361, 35364-35364, 35373-35373, 35375-35375, 35377-35377, 35395-35395, 35398-35398, 35401-35401
Summary by CodeRabbit