feat: database migrations and model foundation for limits by period#60
feat: database migrations and model foundation for limits by period#60alexgarzao wants to merge 4 commits intodevelopfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds DB migrations: appends WEEKLY and CUSTOM to Sequence Diagram(s)mermaid Migrator->>Postgres: Run 000006_add_limit_type_enum_values.up.sql\nALTER TYPE ... ADD VALUE IF NOT EXISTS 'WEEKLY','CUSTOM' Migrator->>Postgres: Run 000007_add_limit_period_columns.up.sql\nALTER TABLE limits ADD columns, constraints, partial index Migrator->>Postgres: Run 000008_add_counter_expires_at.up.sql\nALTER TABLE usage_counters ADD expires_at, partial index Note over Migrator,Postgres: On rollback of enum change: 🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Comment Tip CodeRabbit can generate a title for your PR based on the changes.Add |
|
Consider updating CHANGELOG.md to document this change. If this change doesn't need a changelog entry, add the |
|
This PR is very large (303 files, 46408 lines changed). Consider breaking it into smaller PRs for easier review. |
🔒 Security Scan Results —
|
This comment has been minimized.
This comment has been minimized.
e0468db to
6520921
Compare
6520921 to
3fb9861
Compare
📊 Unit Test Coverage Report:
|
| Metric | Value |
|---|---|
| Overall Coverage | 83.8% |
| Threshold | 85% |
Coverage by Package
| Package | Coverage |
|---|---|
tracer/internal/adapters/cel |
81.9% |
tracer/internal/adapters/http/in/middleware |
62.0% |
tracer/internal/adapters/http/in |
81.8% |
tracer/internal/adapters/postgres/db |
0.0% |
tracer/internal/adapters/postgres |
75.1% |
tracer/internal/services/cache |
95.6% |
tracer/internal/services/command |
81.6% |
tracer/internal/services/query |
78.3% |
tracer/internal/services/workers |
79.7% |
tracer/internal/services |
40.2% |
tracer/pkg/clock |
50.0% |
tracer/pkg/contextutil |
100.0% |
tracer/pkg/logging |
100.0% |
tracer/pkg/migration |
89.0% |
tracer/pkg/model |
97.5% |
tracer/pkg/net/http |
88.3% |
tracer/pkg/resilience |
97.8% |
tracer/pkg/sanitize |
87.1% |
tracer/pkg/validation |
50.0% |
tracer/pkg |
96.6% |
Generated by Go PR Analysis workflow
Add schema changes for WEEKLY, CUSTOM, PER_TRANSACTION limit types: - Migration 000006: add WEEKLY, CUSTOM, PER_TRANSACTION enum values - Migration 000007: add time window and custom period columns - Migration 000008: add counter expires_at column - TimeOfDay value object with JSON serialization and validation - Error constants TRC-0300 to TRC-0312 for new limit validations - FixedClock for MOCK_TIME support in test infrastructure - Limit type constants (LimitTypeWeekly, LimitTypeCustom, etc.)
3fb9861 to
ddc7d1c
Compare
- Remove ErrTimeOfDayInvalidHour/ErrTimeOfDayInvalidMinute (unused after NewTimeOfDay simplification with time.Parse) - Reorganize error codes: TRC-0308~0310 (no gaps in range) - Fix FixedClock.NewTicker stop to be a no-op (matches time.Ticker.Stop which does not close its channel) - Rename TestErrorConstants_DescriptiveMessages to NonEmptyMessages - Update NewTimeOfDay docstring to reflect single-digit hour acceptance
Add ErrTimeOfDayInvalidFormat, ErrLimitUnknownType, ErrLimitCustomPeriodExpired, ErrLimitInvalidCustomStartFormat, ErrLimitInvalidCustomEndFormat to cover all 11 TRC-0300 range constants.
gandalf-at-lerian
left a comment
There was a problem hiding this comment.
Both points addressed — docstring clarifies the single-digit hour → zero-padded String() contract, and FixedClock.NewTicker stop is a clean no-op now. LGTM 👍
PR 1: Database Migrations + Model Foundation
Schema changes for new limit types (WEEKLY, CUSTOM, PER_TRANSACTION), time window columns, custom period columns, and counter expires_at. Introduces TimeOfDay value type and new error constants.
Changes
Migrations:
000006: Add WEEKLY, CUSTOM, PER_TRANSACTION enum values tolimit_type000007: Add time window (active_time_start,active_time_end) and custom period (custom_start_date,custom_end_date) columns with constraints000008: Addexpires_atcolumn tousage_countersModel:
TimeOfDayvalue object with JSON serialization, validation viatime.Parse("15:04"), and comparison methodsLimitTypeWeekly,LimitTypeCustom,LimitTypePERTransaction)FixedClockinpkg/clockfor MOCK_TIME test infrastructureMigration Rollback
All migrations have corresponding
down.sqlfiles:000006: RAISE NOTICE (enum values cannot be dropped if in use)000007: Drops nullable columns safely (no data loss)000008: Dropsexpires_atcolumnNotes