From 79c5bf7726074143417f5b04fc39ff681a95ed34 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Tue, 22 Oct 2024 16:43:10 +0200 Subject: [PATCH] fix: tests --- internal/ledger.go | 2 +- internal/storage/driver/driver.go | 2 ++ internal/storage/driver/migrations.go | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/ledger.go b/internal/ledger.go index e80b4cc72..0f44ab61a 100644 --- a/internal/ledger.go +++ b/internal/ledger.go @@ -179,7 +179,7 @@ func shortenFeature(feature string) string { type Configuration struct { Bucket string `json:"bucket" bun:"bucket,type:varchar(255)"` - Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb"` + Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb,nullzero"` Features FeatureSet `json:"features" bun:"features,type:jsonb"` } diff --git a/internal/storage/driver/driver.go b/internal/storage/driver/driver.go index dafe20fa5..f867eff40 100644 --- a/internal/storage/driver/driver.go +++ b/internal/storage/driver/driver.go @@ -98,6 +98,7 @@ func (d *Driver) UpdateLedgerMetadata(ctx context.Context, name string, m metada Set("metadata = metadata || ?", m). Where("name = ?", name). Exec(ctx) + return err } @@ -124,6 +125,7 @@ func (d *Driver) ListLedgers(ctx context.Context, q ledgercontroller.ListLedgers } func (d *Driver) GetLedger(ctx context.Context, name string) (*ledger.Ledger, error) { + ret := &ledger.Ledger{} if err := d.db.NewSelect(). Model(ret). diff --git a/internal/storage/driver/migrations.go b/internal/storage/driver/migrations.go index 1e250e132..d649ffe75 100644 --- a/internal/storage/driver/migrations.go +++ b/internal/storage/driver/migrations.go @@ -200,6 +200,18 @@ func GetMigrator() *migrations.Migrator { }) }, }, + migrations.Migration{ + Name: "add default on ledgers metadata", + Up: func(ctx context.Context, db bun.IDB) error { + return db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error { + _, err := tx.ExecContext(ctx, ` + alter table _system.ledgers + alter column metadata set default '{}'::jsonb; + `) + return err + }) + }, + }, ) return migrator