You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
we will need to write explicit migrations every time we add, or change a table or column
we will need to create and manage the initial schema used to populate a database
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.
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.
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.
The text was updated successfully, but these errors were encountered:
In #2584 we identified
gorm.AutoMigrate
is the most significant source of time when running tests against postgreSQL. By replacingAutoMigrate
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
:Units of work:
AutoMigrate
Replace the last of AutoMigrate #2862data/migrator
use of gorm heleprs (db.Migrator().HasTable
) Replace gorm.Migrator calls with sql #2846gorm.AutoMigrate
with an initial schema generated from a database dump that we embed withgo:embed
Replace gorm.AutoMigrate with schema.sql #2843Table driven tests
A table driven test has a few advantages:
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.The text was updated successfully, but these errors were encountered: