From a1a55aad99f54bcb294553a5b83fb1fd7145d6ba Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Tue, 22 Oct 2024 17:38:52 +0200 Subject: [PATCH] fix: migrations --- internal/ledger.go | 2 +- internal/storage/driver/migrations.go | 12 ++++++++++++ 2 files changed, 13 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/migrations.go b/internal/storage/driver/migrations.go index 1e250e132..e7581dd3b 100644 --- a/internal/storage/driver/migrations.go +++ b/internal/storage/driver/migrations.go @@ -200,6 +200,18 @@ func GetMigrator() *migrations.Migrator { }) }, }, + migrations.Migration{ + Name: "set default metadata on ledgers", + 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