Skip to content

Commit

Permalink
docs: require dev-url for schema data sources (#126)
Browse files Browse the repository at this point in the history
* docs: require dev-url for schema data sources

* docs: fix ci

* docs: remove dev_db_url
  • Loading branch information
datdao authored Mar 21, 2024
1 parent 95cbb7b commit 547b653
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ provider "atlas" {

2\. Then, inspect the schema of the database:
```shell
atlas schema inspect -d "mysql://root:pass@localhost:3306/example" > schema.hcl
atlas schema inspect -u "mysql://root:pass@localhost:3306/example" > schema.hcl
```

3\. Finally, configure the terraform resource to apply the state to your database:
Expand Down
3 changes: 1 addition & 2 deletions docs/data-sources/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ resource "atlas_schema" "hello" {

### Required

- `dev_url` (String, Sensitive) The url of the dev-db see https://atlasgo.io/cli/url
- `src` (String) The schema definition of the database. This attribute can be HCL schema or an URL to HCL/SQL file.

### Optional

- `dev_db_url` (String, Sensitive, Deprecated) Use `dev_url` instead.
- `dev_url` (String, Sensitive) The url of the dev-db see https://atlasgo.io/cli/url
- `variables` (Map of String) The map of variables used in the HCL.

### Read-Only
Expand Down
1 change: 0 additions & 1 deletion docs/resources/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ resource "atlas_schema" "market" {

### Optional

- `dev_db_url` (String, Sensitive, Deprecated) Use `dev_url` instead.
- `dev_url` (String, Sensitive) The url of the dev-db see https://atlasgo.io/cli/url
- `diff` (Block, Optional) (see [below for nested schema](#nestedblock--diff))
- `exclude` (List of String) Filter out resources matching the given glob pattern. See https://atlasgo.io/declarative/inspect#exclude-schemas
Expand Down
14 changes: 2 additions & 12 deletions internal/provider/atlas_schema_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type (
HCL types.String `tfsdk:"hcl"`
ID types.String `tfsdk:"id"`
Variables types.Map `tfsdk:"variables"`

DeprecatedDevURL types.String `tfsdk:"dev_db_url"`
}
)

Expand Down Expand Up @@ -58,7 +56,7 @@ func (d *AtlasSchemaDataSource) Schema(_ context.Context, _ datasource.SchemaReq
Attributes: map[string]schema.Attribute{
"dev_url": schema.StringAttribute{
Description: "The url of the dev-db see https://atlasgo.io/cli/url",
Optional: true,
Required: true,
Sensitive: true,
},
"src": schema.StringAttribute{
Expand All @@ -79,14 +77,6 @@ func (d *AtlasSchemaDataSource) Schema(_ context.Context, _ datasource.SchemaReq
Optional: true,
ElementType: types.StringType,
},

"dev_db_url": schema.StringAttribute{
Description: "Use `dev_url` instead.",
Optional: true,
Sensitive: true,
DeprecationMessage: "This attribute is deprecated and will be removed in the next major version. " +
"Please use the `dev_url` attribute instead.",
},
},
}
}
Expand Down Expand Up @@ -146,7 +136,7 @@ func (d *AtlasSchemaDataSource) Read(ctx context.Context, req datasource.ReadReq
}
}
normalHCL, err := d.client.SchemaInspect(ctx, &atlas.SchemaInspectParams{
DevURL: d.getDevURL(data.DevURL, data.DeprecatedDevURL),
DevURL: d.getDevURL(data.DevURL),
Format: "hcl",
URL: src,
Vars: vars,
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/atlas_schema_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestAccSchemaDataSource(t *testing.T) {
// Read testing
{
Config: fmt.Sprintf(`data "atlas_schema" "market" {
dev_db_url = "mysql://root:pass@localhost:3307/test"
dev_url = "mysql://root:pass@localhost:3307/test"
variables = {
tenant = "test",
}
Expand All @@ -76,7 +76,7 @@ func TestAccSchemaDataSource(t *testing.T) {
// Read testing
{
Config: `data "atlas_schema" "market" {
dev_db_url = "mysql://root:pass@localhost:3307/test"
dev_url = "mysql://root:pass@localhost:3307/test"
src = ""
}`,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -117,6 +117,7 @@ func TestAccSchemaDataSource(t *testing.T) {
}
data "atlas_schema" "hello" {
src = "file://./sql-files/schema.sql"
dev_url = "mysql://root:pass@localhost:3307/test"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.atlas_schema.hello", "hcl", normalHCL),
Expand Down
13 changes: 2 additions & 11 deletions internal/provider/atlas_schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type (
TxMode types.String `tfsdk:"tx_mode"`
// Policies
Diff *Diff `tfsdk:"diff"`

DeprecatedDevURL types.String `tfsdk:"dev_db_url"`
}
// Diff defines the diff policies to apply when planning schema changes.
Diff struct {
Expand Down Expand Up @@ -174,13 +172,6 @@ func (r *AtlasSchemaResource) Schema(ctx context.Context, _ resource.SchemaReque
stringplanmodifier.UseStateForUnknown(),
},
},
"dev_db_url": schema.StringAttribute{
Description: "Use `dev_url` instead.",
Optional: true,
Sensitive: true,
DeprecationMessage: "This attribute is deprecated and will be removed in the next major version. " +
"Please use the `dev_url` attribute instead.",
},
},
}
}
Expand Down Expand Up @@ -306,7 +297,7 @@ func (r *AtlasSchemaResource) ModifyPlan(ctx context.Context, req resource.Modif
return
}
}
resp.Diagnostics.Append(PrintPlanSQL(ctx, r.client, r.getDevURL(plan.DevURL, plan.DeprecatedDevURL), plan)...)
resp.Diagnostics.Append(PrintPlanSQL(ctx, r.client, r.getDevURL(plan.DevURL), plan)...)
}

func PrintPlanSQL(ctx context.Context, c *atlas.Client, devURL string, data *AtlasSchemaResourceModel) (diags diag.Diagnostics) {
Expand Down Expand Up @@ -385,7 +376,7 @@ func (r *AtlasSchemaResource) applySchema(ctx context.Context, data *AtlasSchema
}
d := &schemaData{
URL: u,
DevURL: r.getDevURL(data.DevURL, data.DeprecatedDevURL),
DevURL: r.getDevURL(data.DevURL),
Source: "schema.hcl",
Diff: data.Diff,
}
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/atlas_schema_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "foo_mirror" "url" {
value = "%s"
}
data "atlas_schema" "market" {
dev_db_url = "%s"
dev_url = "%s"
src = <<-EOT
schema "test" {
charset = "utf8mb4"
Expand All @@ -55,13 +55,13 @@ data "atlas_schema" "market" {
resource "atlas_schema" "testdb" {
hcl = data.atlas_schema.market.hcl
url = foo_mirror.url.result
dev_db_url = "%s"
dev_url = "%s"
}
`, mysqlURL, mysqlDevURL, mysqlDevURL)

var testAccActionConfigUpdate = fmt.Sprintf(`
data "atlas_schema" "market" {
dev_db_url = "%s"
dev_url = "%s"
src = <<-EOT
schema "test" {
charset = "utf8mb4"
Expand Down Expand Up @@ -355,7 +355,7 @@ schema "test" {
}
testAccSanityT = `
data "atlas_schema" "sanity" {
dev_db_url = "%s"
dev_url = "%s"
src = <<-EOT
%s
EOT
Expand Down

0 comments on commit 547b653

Please sign in to comment.