Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AutoAliasing code migration #39

Merged
merged 8 commits into from
Apr 17, 2023
Merged

Add AutoAliasing code migration #39

merged 8 commits into from
Apr 17, 2023

Conversation

aq17
Copy link
Contributor

@aq17 aq17 commented Apr 14, 2023

This PR adds an option to perform code migrations on providers, either alongside a normal provider updates (by default or if --kind=all), or by itself (if --kind=code).
If --kind=all, all available code migrations options will be performed.
If --kind=code, a list of options must be specified via --migration-opts.

Currently the only option is to add AutoAliasing.

@aq17
Copy link
Contributor Author

aq17 commented Apr 14, 2023

upgrade/migrations.go Outdated Show resolved Hide resolved
upgrade/migrations.go Outdated Show resolved Hide resolved
upgrade/migrations.go Outdated Show resolved Hide resolved
`

// Write original program to temporary file
orig, err := os.Create("original.go")
Copy link
Member

Choose a reason for hiding this comment

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

If we need to write to a temp file, at least put it in temporary directory. Ideally, we would be able to do the test in memory though.

upgrade/migrations_test.go Outdated Show resolved Hide resolved
"github.com/stretchr/testify/assert"
)

func TestAutoAliasingMigration(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make sure we can run AutoAliasing multiple times on a file without changes. We should write migrations with the expectation that they will be run on every provider every time.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like that is handled by another part of the migration. Can we get a test for that part as well?

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

A couple nits, but otherwise LGTM

upgrade/upgrade-provider.go Outdated Show resolved Hide resolved
@@ -197,6 +216,30 @@ func UpgradeProvider(ctx Context, name string) error {
In(repo.providerDir()))
}

if ctx.UpgradeCodeMigration {
applied := make(map[string]struct{})
for _, opt := range ctx.MigrationOpts {
Copy link
Member

Choose a reason for hiding this comment

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

We should make sure this is sorted so we get the same output however the user specifies the migrations.

upgrade/migrations.go Outdated Show resolved Hide resolved
@aq17 aq17 merged commit 25407c5 into main Apr 17, 2023
@aq17 aq17 deleted the aqiu/ast branch April 17, 2023 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants