diff --git a/docs/resources/migration.md b/docs/resources/migration.md index 3600cdb..b8080ec 100644 --- a/docs/resources/migration.md +++ b/docs/resources/migration.md @@ -34,6 +34,7 @@ resource "atlas_migration" "hello" { ### Optional +- `baseline` (String) An optional version to start the migration history from. See https://atlasgo.io/versioned/apply#existing-databases - `cloud` (Block, Optional) (see [below for nested schema](#nestedblock--cloud)) - `dev_url` (String, Sensitive) The url of the dev-db see https://atlasgo.io/cli/url - `dir` (String) the URL of the migration directory. dir or remote_dir block is required diff --git a/internal/provider/atlas_migration_resource.go b/internal/provider/atlas_migration_resource.go index 0384589..7a7df80 100644 --- a/internal/provider/atlas_migration_resource.go +++ b/internal/provider/atlas_migration_resource.go @@ -32,6 +32,7 @@ type ( DevURL types.String `tfsdk:"dev_url"` RevisionsSchema types.String `tfsdk:"revisions_schema"` Version types.String `tfsdk:"version"` + Baseline types.String `tfsdk:"baseline"` Cloud *AtlasCloudBlock `tfsdk:"cloud"` RemoteDir *RemoteDirBlock `tfsdk:"remote_dir"` @@ -99,6 +100,10 @@ func (r *MigrationResource) Schema(_ context.Context, _ resource.SchemaRequest, Optional: true, Sensitive: true, }, + "baseline": schema.StringAttribute{ + Description: "An optional version to start the migration history from. See https://atlasgo.io/versioned/apply#existing-databases", + Optional: true, + }, "revisions_schema": schema.StringAttribute{ Description: "The name of the schema the revisions table resides in", Optional: true, @@ -467,6 +472,7 @@ func (d *MigrationResourceModel) AtlasHCL(name string, devURL string, cloud *Atl URL: d.URL.ValueString(), DevURL: defaultString(d.DevURL, devURL), DirURL: d.DirURL.ValueStringPointer(), + Baseline: d.Baseline.ValueString(), RevisionsSchema: d.RevisionsSchema.ValueString(), } if d.Cloud != nil && d.Cloud.Token.ValueString() != "" { diff --git a/internal/provider/config/migrate.tmpl b/internal/provider/config/migrate.tmpl index ec61fe4..5492153 100644 --- a/internal/provider/config/migrate.tmpl +++ b/internal/provider/config/migrate.tmpl @@ -45,6 +45,9 @@ env { {{- else }} dir = "file://{{ or .DirURL "migrations" }}" {{- end }} +{{- if .Baseline }} + baseline = "{{ .Baseline }}" +{{- end }} {{- if .RevisionsSchema }} revisions_schema = "{{ .RevisionsSchema }}" {{- end }} diff --git a/internal/provider/template.go b/internal/provider/template.go index f7f1759..f1034d5 100644 --- a/internal/provider/template.go +++ b/internal/provider/template.go @@ -26,6 +26,7 @@ type ( DirURL *string RemoteDir *remoteDir + Baseline string RevisionsSchema string } ) diff --git a/internal/provider/template_test.go b/internal/provider/template_test.go index e522bac..7cdb46d 100644 --- a/internal/provider/template_test.go +++ b/internal/provider/template_test.go @@ -35,6 +35,10 @@ func TestTemplate(t *testing.T) { {name: "local", data: templateData{ URL: "mysql://user:pass@localhost:3306/tf-db", }}, + {name: "baseline", data: templateData{ + URL: "mysql://user:pass@localhost:3306/tf-db", + Baseline: "100000", + }}, {name: "cloud-no-token", data: templateData{ URL: "mysql://user:pass@localhost:3306/tf-db", RemoteDir: &remoteDir{ diff --git a/internal/provider/testdata/TestTemplate/baseline-cfg.hcl b/internal/provider/testdata/TestTemplate/baseline-cfg.hcl new file mode 100644 index 0000000..61463aa --- /dev/null +++ b/internal/provider/testdata/TestTemplate/baseline-cfg.hcl @@ -0,0 +1,20 @@ + + +env { + name = atlas.env + url = "mysql://user:pass@localhost:3306/tf-db" + migration { + dir = "file://migrations" + baseline = "100000" + } + format { + migrate { + apply = "{{ json . }}" + lint = "{{ json . }}" + status = "{{ json . }}" + } + } + lint { + format = "{{ json . }}" + } +}