Skip to content

Commit

Permalink
atlasmigration: added execOrder for CRDs (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Nov 20, 2023
1 parent 8931e1f commit 7211951
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/atlasmigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type (
RevisionsSchema string `json:"revisionsSchema,omitempty"`
// BaselineVersion defines the baseline version of the database on the first migration.
Baseline string `json:"baseline,omitempty"`
// ExecOrder controls how Atlas computes and executes pending migration files to the database.
// +kubebuilder:default=linear
ExecOrder MigrateExecOrder `json:"execOrder,omitempty"`
}
// Cloud defines the Atlas Cloud configuration.
Cloud struct {
Expand Down Expand Up @@ -98,6 +101,10 @@ type (
}
)

// ExecOrder controls how Atlas computes and executes pending migration files to the database.
// +kubebuilder:validation:Enum=linear;linear-skip;non-linear
type MigrateExecOrder string

const (
readyCond = "Ready"
)
Expand Down
9 changes: 9 additions & 0 deletions charts/atlas-operator/templates/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ spec:
description: EnvName sets the environment name used for reporting
runs to Atlas Cloud.
type: string
execOrder:
default: linear
description: ExecOrder controls how Atlas computes and executes pending
migration files to the database.
enum:
- linear
- linear-skip
- non-linear
type: string
revisionsSchema:
description: RevisionsSchema defines the schema that revisions table
resides in
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/db.atlasgo.io_atlasmigrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ spec:
description: EnvName sets the environment name used for reporting
runs to Atlas Cloud.
type: string
execOrder:
default: linear
description: ExecOrder controls how Atlas computes and executes pending
migration files to the database.
enum:
- linear
- linear-skip
- non-linear
type: string
revisionsSchema:
description: RevisionsSchema defines the schema that revisions table
resides in
Expand Down
2 changes: 2 additions & 0 deletions controllers/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type (
Cloud *cloud
RevisionsSchema string
Baseline string
ExecOrder string
}
cloud struct {
URL string
Expand Down Expand Up @@ -272,6 +273,7 @@ func (r *AtlasMigrationReconciler) extractData(ctx context.Context, res *dbv1alp
EnvName: defaultEnvName,
RevisionsSchema: s.RevisionsSchema,
Baseline: s.Baseline,
ExecOrder: string(s.ExecOrder),
}
)
if env := s.EnvName; env != "" {
Expand Down
6 changes: 6 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var (
tmpls embed.FS
tmpl = template.Must(template.New("operator").
Funcs(template.FuncMap{
"hclValue": func(s string) string {
if s == "" {
return s
}
return strings.ReplaceAll(strings.ToUpper(s), "-", "_")
},
"slides": func(s []string) string {
b := &strings.Builder{}
b.WriteRune('[')
Expand Down
7 changes: 5 additions & 2 deletions controllers/templates/atlas_migration.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ env {
{{- else }}
dir = "file://migrations"
{{- end }}
{{- if .RevisionsSchema }}
revisions_schema = "{{ .RevisionsSchema }}"
{{- if .ExecOrder }}
exec_order = {{ hclValue .ExecOrder }}
{{- end }}
{{- if .Baseline }}
baseline = "{{ .Baseline }}"
{{- end }}
{{- if .RevisionsSchema }}
revisions_schema = "{{ .RevisionsSchema }}"
{{- end }}
}
}

0 comments on commit 7211951

Please sign in to comment.