Skip to content

Commit

Permalink
add support for baseline on migrate (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen authored Nov 12, 2023
1 parent b4e8454 commit 037dd71
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1alpha1/migration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type FlywayConfiguration struct {
// See https://documentation.red-gate.com/fd/default-schema-184127496.html
// +kubebuilder:validation:Optional
DefaultSchema *string `json:"defaultSchema"`

// Base-line on migrate.
// See https://documentation.red-gate.com/fd/baseline-on-migrate-224919695.html
// +kubebuilder:validation:Optional
BaselineOnMigrate *bool `json:"baselineOnMigrate"`
}

// MigrationSource defines the source for the flyway-migrations.
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/flyway.davidkarlsen.com_migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ spec:
flywayConfiguration:
description: settings for flyway
properties:
baselineOnMigrate:
description: Base-line on migrate. See https://documentation.red-gate.com/fd/baseline-on-migrate-224919695.html
type: boolean
commands:
default:
- info
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/jobutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package controller

import (
"fmt"
"strconv"

"github.com/caitlinelfring/go-env-default"
flywayv1alpha1 "github.com/davidkarlsen/flyway-operator/api/v1alpha1"
"github.com/samber/lo"
Expand Down Expand Up @@ -77,6 +79,13 @@ func createJobSpec(migration *flywayv1alpha1.Migration) *batchv1.Job {
},
}

if migration.Spec.FlywayConfiguration.BaselineOnMigrate != nil {
envVars = append(envVars, corev1.EnvVar{
Name: "FLYWAY_BASELINE_ON_MIGRATE",
Value: strconv.FormatBool(*migration.Spec.FlywayConfiguration.BaselineOnMigrate),
})
}

if migration.Spec.FlywayConfiguration.DefaultSchema != nil {
envVars = append(envVars, corev1.EnvVar{
Name: "FLYWAY_DEFAULT_SCHEMA",
Expand Down
8 changes: 7 additions & 1 deletion internal/controller/migration_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package controller

import (
"context"
"testing"

flywayv1alpha1 "github.com/davidkarlsen/flyway-operator/api/v1alpha1"
"github.com/gophercloud/gophercloud/testhelper"
"github.com/redhat-cop/operator-utils/pkg/util"
Expand All @@ -11,9 +13,9 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/record"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"testing"
)

func TestGithubactionRunnerController(t *testing.T) {
Expand All @@ -26,6 +28,10 @@ func TestGithubactionRunnerController(t *testing.T) {
Namespace: namespace,
},
Spec: flywayv1alpha1.MigrationSpec{
FlywayConfiguration: flywayv1alpha1.FlywayConfiguration{
BaselineOnMigrate: pointer.Bool(true),
DefaultSchema: pointer.String("someSchema"),
},
Database: flywayv1alpha1.Database{
Username: "someUser",
Credentials: corev1.SecretKeySelector{},
Expand Down

0 comments on commit 037dd71

Please sign in to comment.