From e53fd2c9a5dad2e92d06fe242a1323348728ffe9 Mon Sep 17 00:00:00 2001 From: SoXX Date: Wed, 6 Nov 2024 10:55:47 +0100 Subject: [PATCH] feat(migration): added migration toggle --- pkg/database/client.go | 8 +++++--- pkg/models/config.go | 1 + test/helper.go | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/database/client.go b/pkg/database/client.go index 1fadda5..7618372 100644 --- a/pkg/database/client.go +++ b/pkg/database/client.go @@ -70,9 +70,11 @@ func Connect(ctx context.Context, config models.DatabaseConfig) error { return utils.HandleError(ctx, span, localLogger, err) } - err = migrateDatabase(ctx, sqlDB, config) - if err != nil { - return utils.HandleError(ctx, span, localLogger, err) + if config.Migrate { + err = migrateDatabase(ctx, sqlDB, config) + if err != nil { + return utils.HandleError(ctx, span, localLogger, err) + } } client = sqlDB diff --git a/pkg/models/config.go b/pkg/models/config.go index 2013b95..e98a58f 100644 --- a/pkg/models/config.go +++ b/pkg/models/config.go @@ -9,4 +9,5 @@ type DatabaseConfig struct { SSL bool `env:"DB_SSL,required" envDefault:"true"` Timezone string `env:"DB_TIMEZONE,required" envDefault:"Europe/Berlin"` Debug bool `env:"DB_DEBUG" envDefault:"false"` + Migrate bool } diff --git a/test/helper.go b/test/helper.go index 49155fa..aa12b0e 100644 --- a/test/helper.go +++ b/test/helper.go @@ -121,6 +121,7 @@ func DatabaseModesFromConnectionString(ctx context.Context, pgContainer *postgre SSL: false, Timezone: "Europe/Berlin", Debug: true, + Migrate: true, } return databaseConfig, nil