Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
// Package maintenance holds Temporal workflows and activities for
|
|
// cross-cutting database maintenance — currently the recurring ensure pass
|
|
// that keeps core.webhook_events' monthly RANGE partitions provisioned
|
|
// ahead of need (design.md D3, webhook-partition-maintenance spec).
|
|
package maintenance
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/db"
|
|
)
|
|
|
|
// Activities holds dependencies for webhook_events partition-maintenance
|
|
// activities.
|
|
type Activities struct {
|
|
database *sql.DB
|
|
logger *slog.Logger
|
|
}
|
|
|
|
// NewActivities constructs an Activities ready for registration.
|
|
func NewActivities(database *sql.DB, logger *slog.Logger) *Activities {
|
|
if logger == nil {
|
|
logger = slog.Default()
|
|
}
|
|
return &Activities{database: database, logger: logger}
|
|
}
|
|
|
|
// EnsureWebhookPartitionsOutput reports one ensure pass.
|
|
type EnsureWebhookPartitionsOutput struct {
|
|
MonthsAhead int
|
|
}
|
|
|
|
// EnsureWebhookPartitionsActivity creates any missing monthly RANGE
|
|
// partitions of core.webhook_events for the current month through
|
|
// db.DefaultWebhookPartitionMonthsAhead months ahead. It is idempotent
|
|
// (CREATE TABLE IF NOT EXISTS), so re-running it — on the recurring
|
|
// schedule this backs, or racing the console's own boot pass — changes
|
|
// nothing it should not.
|
|
func (a *Activities) EnsureWebhookPartitionsActivity(ctx context.Context) (EnsureWebhookPartitionsOutput, error) {
|
|
monthsAhead := db.DefaultWebhookPartitionMonthsAhead
|
|
if err := db.EnsureWebhookEventPartitions(ctx, a.database, time.Now(), monthsAhead); err != nil {
|
|
if a.logger != nil {
|
|
a.logger.Warn("webhook_events partition ensure failed", slog.Any("error", err))
|
|
}
|
|
return EnsureWebhookPartitionsOutput{}, err
|
|
}
|
|
return EnsureWebhookPartitionsOutput{MonthsAhead: monthsAhead}, nil
|
|
}
|