-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add tenant_schedule database table for manifest-driven scheduling #2148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bjcoombs
merged 4 commits into
develop
from
per-tenant-scheduling--8--tenant-schedule-table
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e5a0e2b
feat: add tenant_schedule database table for manifest-driven scheduling
bjcoombs fea8fbe
test: add coverage for TenantScheduleEntity TableName and struct fields
bjcoombs e337c9c
Merge remote-tracking branch 'origin/develop' into per-tenant-schedul…
bjcoombs 669d609
Merge remote-tracking branch 'origin/develop' into per-tenant-schedul…
bjcoombs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Package scheduling provides persistence types for tenant-level cron schedules. | ||
| package scheduling | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| // TenantScheduleEntity is the GORM entity for the tenant_schedule table. | ||
| // This table lives in per-tenant schemas and bridges manifest scheduled: triggers | ||
| // to the CronScheduler infrastructure. | ||
| type TenantScheduleEntity struct { | ||
| ID uuid.UUID `gorm:"column:id;type:uuid;primaryKey;default:gen_random_uuid()"` | ||
| ScheduleName string `gorm:"column:schedule_name;type:varchar(128);not null;uniqueIndex:uq_tenant_schedule_name"` | ||
| SagaName string `gorm:"column:saga_name;type:varchar(128);not null"` | ||
| CronExpr string `gorm:"column:cron_expr;type:varchar(64);not null"` | ||
| Enabled bool `gorm:"column:enabled;not null;default:true"` | ||
| ManifestVersionID *uuid.UUID `gorm:"column:manifest_version_id;type:uuid"` | ||
| Metadata *string `gorm:"column:metadata;type:jsonb"` | ||
| CreatedAt time.Time `gorm:"column:created_at;not null;autoCreateTime"` | ||
| UpdatedAt time.Time `gorm:"column:updated_at;not null;autoUpdateTime"` | ||
| } | ||
|
|
||
| // TableName returns the table name for GORM. | ||
| func (TenantScheduleEntity) TableName() string { | ||
| return "tenant_schedule" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package scheduling | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestTenantScheduleEntity_TableName(t *testing.T) { | ||
| e := TenantScheduleEntity{} | ||
| assert.Equal(t, "tenant_schedule", e.TableName()) | ||
| } | ||
|
|
||
| func TestTenantScheduleEntity_Fields(t *testing.T) { | ||
| id := uuid.New() | ||
| versionID := uuid.New() | ||
| meta := `{"key":"value"}` | ||
| now := time.Now() | ||
|
|
||
| e := TenantScheduleEntity{ | ||
| ID: id, | ||
| ScheduleName: "daily-billing", | ||
| SagaName: "billing.run_daily", | ||
| CronExpr: "0 0 * * *", | ||
| Enabled: true, | ||
| ManifestVersionID: &versionID, | ||
| Metadata: &meta, | ||
| CreatedAt: now, | ||
| UpdatedAt: now, | ||
| } | ||
|
|
||
| assert.Equal(t, id, e.ID) | ||
| assert.Equal(t, "daily-billing", e.ScheduleName) | ||
| assert.Equal(t, "billing.run_daily", e.SagaName) | ||
| assert.Equal(t, "0 0 * * *", e.CronExpr) | ||
| assert.True(t, e.Enabled) | ||
| assert.Equal(t, &versionID, e.ManifestVersionID) | ||
| assert.Equal(t, &meta, e.Metadata) | ||
| } |
23 changes: 23 additions & 0 deletions
23
services/control-plane/migrations/20260406000001_create_tenant_schedule.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| -- Tenant Schedule table for manifest-driven cron scheduling. | ||
| -- Written by manifest application, read by ScheduleProvider. | ||
| -- Multi-tenancy: Schema-per-tenant architecture means no tenant_id column needed. | ||
| -- manifest_version_id is a soft cross-schema reference for audit/debugging - no FK constraint. | ||
|
|
||
| CREATE TABLE tenant_schedule ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| schedule_name VARCHAR(128) NOT NULL, | ||
| saga_name VARCHAR(128) NOT NULL, | ||
| cron_expr VARCHAR(64) NOT NULL, | ||
| enabled BOOLEAN NOT NULL DEFAULT TRUE, | ||
| manifest_version_id UUID, | ||
| metadata JSONB, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| CONSTRAINT uq_tenant_schedule_name UNIQUE (schedule_name) | ||
| ); | ||
|
|
||
| -- Index for ScheduleProvider to load all enabled schedules efficiently. | ||
| CREATE INDEX idx_tenant_schedule_enabled ON tenant_schedule (enabled); | ||
|
|
||
| -- Index for manifest applier to look up schedules by saga. | ||
| CREATE INDEX idx_tenant_schedule_saga_name ON tenant_schedule (saga_name); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.