Skip to content

Conversation

@bplunkett-stripe
Copy link
Collaborator

@bplunkett-stripe bplunkett-stripe commented Mar 30, 2025

Description

Changes:

  • Allow users to generate plans FROM a schema directory
  • Allow both the from and to databases to be schema directories IF the user provides a temporary database
  • Switch commands to print through the cobra.Command proxy
  • Spin out tests for the plan and apply commands. Testing these manually was getting too complex

Motivation

#198

Testing

Added tests for these core commands because it was getting too complicated to run manually. This does not all cover all cases, but it covers core usages.

@bplunkett-stripe bplunkett-stripe added the enhancement New feature or request label Mar 30, 2025
@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/plan-flexible-source branch from a618915 to e1c79cc Compare March 30, 2025 03:02
}

fmt.Println(planFlags.outputFormat.convertToOutputString(plan))
cmd.Println(outputFmt.convertToOutputString(plan))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonically, all logs should be done through the command. We were just doing this wrong previously. This is how cobra does it's own logging (e.g., printing usage)

return err
} else if len(plan.Statements) == 0 {
fmt.Println("Schema matches expected. No plan generated")
cmd.Println("Schema matches expected. No plan generated")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonically, all logs should be done through the command. We were just doing this wrong previously. This is how cobra does it's own logging (e.g., printing usage)

@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/plan-flexible-source branch from 7d25b39 to ac4fc9e Compare March 31, 2025 04:57
result["host"] = e.sockPath
result["user"] = e.superuser
result["port"] = strconv.Itoa(defaultPort)
result[ConnectionOptionHost] = e.sockPath
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed so tests can access them for the --{from/to}-empty-dsn parameters

dsnFlagName string

// isEmptyDsnUsingPq indicates to connect via DSN using the pq environment variables and defaults.
isEmptyDsnUsingPq bool
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was requested per this PR. This maintains support but makes it more explicit and flexible

@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/plan-flexible-source branch from ac4fc9e to abfe62d Compare March 31, 2025 05:06
@bplunkett-stripe bplunkett-stripe changed the title [FEATURE] Add support for "--from-schema-dir" in plan and providing a custom temporary database [FEATURE] Add support for --from-dir and providing a dedicated temporary database server Mar 31, 2025
Copy link
Collaborator

@alexaub-stripe alexaub-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment worth looking at, but nothing blocking! Looks great!

if err != nil {
return planConfig{}, err
func parseSchemaSource(p schemaSourceFactoryFlags) (schemaSourceFactory, error) {
// Store result in a var instead of returning early to ensure only one option is set.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just early return if not len(p.schemaDirs) > 0 XOR p.connFlags.IsSet()? Should remove a couple of the ssf nil check error blocks below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this approach because it scales slightly better. If you put the condition at the top like you suggest then we are duplicating the condition, meaning they can become out of alignment.

You can imagine this gets more painful if we scale to 3 separate cases. Imagine a new schema source type that we use if foobarParams != "". We would then need to add it in two separate places with the approach you suggest

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to go with this, though I think you sacrifice some readability in order to avoid that duplication of the checks.

Half joking but I wonder if pushing ssf's onto a result slice and then waiting til the end to check if there isn't exactly one would be the best of both worlds. No need to do ssf != nil checks on each case.

Copy link
Collaborator Author

@bplunkett-stripe bplunkett-stripe Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to go with this, though I think you sacrifice some readability in order to avoid that duplication of the checks.

Too true

Half joking but I wonder if pushing ssf's onto a result slice and then waiting til the end to check if there isn't exactly one would be the best of both worlds. No need to do ssf != nil checks on each case.

I half agree 😎

@bplunkett-stripe bplunkett-stripe merged commit d5804a3 into main Mar 31, 2025
10 checks passed
@bplunkett-stripe bplunkett-stripe deleted the bplunkett/plan-flexible-source branch March 31, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants