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

Replace gorm.AutoMigrate #2768

Closed
5 tasks done
dnephin opened this issue Jul 28, 2022 · 0 comments · Fixed by #2862
Closed
5 tasks done

Replace gorm.AutoMigrate #2768

dnephin opened this issue Jul 28, 2022 · 0 comments · Fixed by #2862
Assignees

Comments

@dnephin
Copy link
Contributor

dnephin commented Jul 28, 2022

In #2584 we identified gorm.AutoMigrate is the most significant source of time when running tests against postgreSQL. By replacing AutoMigrate we can more easily run all of our tests against postgreSQL. Removing it will also give us a much clearer picture of the SQL that is being used to construct and modify our database tables.

However, there are two consequence to removing AutoMigrate:

  1. we will need to write explicit migrations every time we add, or change a table or column
  2. we will need to create and manage the initial schema used to populate a database

Units of work:

Table driven tests

A table driven test has a few advantages:

  1. it lets us easily compare the list of migrations to the list of test cases for migrations. This gives us the opportunity to prompt the contributor to add a test case when they are adding a migration. If the list of migrations contains an ID that isn't in the list of test cases we can fail the test and indicate they should add a test case.
  2. we can run each migration from a database initialized by running all previous migrations. This removes the need to dump the schema for a database every time we write a migration test. We'll only need to dump a new schema when we remove old migrations.
  3. we'll also be able to leverage this table test to either dump the fully migrated schema (which we'll embed using go:embed) for initializing new databases, or if we decide to keep the schema in the Go source, we can use the test to assert that the migrated schema is identical to the schema stored in the Go source.
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 a pull request may close this issue.

1 participant