From 49ef99d19351507135a2a46775db9ecd82b0eefe Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 1 Dec 2024 17:25:21 -0500 Subject: [PATCH] Add interval method --- pkg/cmd/admin/database.go | 12 ++---------- pkg/database/partman/partman.go | 5 +++++ sql/postgres/migrations/001_initial.up.sql | 2 -- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/admin/database.go b/pkg/cmd/admin/database.go index 075715d..7e9f765 100644 --- a/pkg/cmd/admin/database.go +++ b/pkg/cmd/admin/database.go @@ -11,7 +11,6 @@ import ( "dynatron.me/x/stillbox/pkg/database/partman" "github.com/jackc/pgx/v5" - "github.com/jackc/pgx/v5/pgconn" "github.com/urfave/cli/v2" ) @@ -54,11 +53,6 @@ func partitioningCommand(cfg *config.Config) *cli.Command { } func Repartition(ctx context.Context, db database.Store, cfg config.Partition) error { - cfgIntv := partman.Interval(cfg.Interval) - if !cfgIntv.IsValid() { - return fmt.Errorf("invalid partitioning interval '%s'", string(cfgIntv)) - } - pm, err := partman.New(db, cfg) if err != nil { return err @@ -86,14 +80,12 @@ func Repartition(ctx context.Context, db database.Store, cfg config.Partition) e } } - if cfgIntv == intv { - fmt.Fprintf(os.Stderr, "config interval '%s' and all extant, attached partitions agree; doing nothing\n", string(cfgIntv)) + if pm.Interval() == intv { + fmt.Fprintf(os.Stderr, "config interval '%s' and all extant, attached partitions agree; doing nothing\n", string(pm.Interval())) return nil } - panic("not implemented") - return nil }, pgx.TxOptions{}) } diff --git a/pkg/database/partman/partman.go b/pkg/database/partman/partman.go index 3676cec..a4b4cd1 100644 --- a/pkg/database/partman/partman.go +++ b/pkg/database/partman/partman.go @@ -93,6 +93,7 @@ func (p Interval) IsValid() bool { type PartitionManager interface { Go(ctx context.Context) Check(ctx context.Context, now time.Time) error + Interval() Interval ExistingPartitions(parts []database.PartitionResult) ([]Partition, error) } @@ -102,6 +103,10 @@ type partman struct { intv Interval } +func (pm *partman) Interval() Interval { + return pm.intv +} + type Partition struct { ParentTable string Schema string diff --git a/sql/postgres/migrations/001_initial.up.sql b/sql/postgres/migrations/001_initial.up.sql index 4f493b0..0d02161 100644 --- a/sql/postgres/migrations/001_initial.up.sql +++ b/sql/postgres/migrations/001_initial.up.sql @@ -161,5 +161,3 @@ CREATE TABLE IF NOT EXISTS incidents_calls( FOREIGN KEY (calls_tbl_id, call_date) REFERENCES calls(id, call_date), PRIMARY KEY (incident_id, call_id) ); - -