feat(assessment): add immutable family versions and the demo bank loader
This commit is contained in:
1 parent
94488e2b57
commit
204c6bae62
28 files changed
+6269
-9
No files matched your search
@@ -36,11 +36,14 @@ const (
|
||||
// organizationMigrationVersion creates organizationTableNames and
|
||||
// organizationFunctionNames.
|
||||
organizationMigrationVersion = 10
|
||||
// assessmentBankMigrationVersion creates assessmentBankTableNames and
|
||||
// assessmentBankFunctionNames.
|
||||
assessmentBankMigrationVersion = 11
|
||||
)
|
||||
|
||||
var (
|
||||
// Tables created by 00001, 00002, 00003, 00005, 00006, 00007, 00008, and
|
||||
// 00010.
|
||||
// 00010, and 00011.
|
||||
outboxTables = []string{"outbox_events"}
|
||||
identityTableNames = []string{"users", "email_tokens", "sessions"}
|
||||
policyTableNames = []string{"policy_versions"}
|
||||
@@ -50,10 +53,16 @@ var (
|
||||
scheduledJobTableNames = []string{"scheduled_jobs"}
|
||||
// organizationTableNames lists the tables of migration 00010.
|
||||
organizationTableNames = []string{"organizations", "organization_representatives", "memberships"}
|
||||
// Trigger functions created by 00003, 00006, and 00010.
|
||||
policyFunctionNames = []string{"policy_versions_refuse_change()", "policy_versions_stamp_creation()"}
|
||||
deliveryFunctionNames = []string{"deliveries_refuse_content_change()", "delivery_attempts_refuse_update()"}
|
||||
organizationFunctionNames = []string{"organizations_require_owner()"}
|
||||
// assessmentBankTableNames lists the tables of migration 00011.
|
||||
assessmentBankTableNames = []string{"assessment_families", "assessment_category_openings"}
|
||||
// Trigger functions created by 00003, 00006, 00010, and 00011.
|
||||
policyFunctionNames = []string{"policy_versions_refuse_change()", "policy_versions_stamp_creation()"}
|
||||
deliveryFunctionNames = []string{"deliveries_refuse_content_change()", "delivery_attempts_refuse_update()"}
|
||||
organizationFunctionNames = []string{"organizations_require_owner()"}
|
||||
assessmentBankFunctionNames = []string{
|
||||
"assessment_families_stamp_creation()", "assessment_families_guard_update()", "assessment_families_refuse_removal()",
|
||||
"assessment_category_openings_stamp()", "assessment_category_openings_refuse_change()",
|
||||
}
|
||||
)
|
||||
|
||||
func TestPostgresMigrations(t *testing.T) {
|
||||
@@ -89,9 +98,11 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertTablesExist(ctx, t, pool, true, scheduledJobTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, organizationTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, organizationFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, assessmentBankTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, assessmentBankFunctionNames...)
|
||||
|
||||
identityRolledBack, policyRolledBack, consumerRolledBack, deliveryRolledBack, mailQuotaRolledBack := false, false, false, false, false
|
||||
scheduledJobRolledBack, organizationRolledBack := false, false
|
||||
scheduledJobRolledBack, organizationRolledBack, assessmentBankRolledBack := false, false, false
|
||||
for rolledBack := 0; ; rolledBack++ {
|
||||
result, err := migrator.DownOne(ctx)
|
||||
if errors.Is(err, postgresadapter.ErrNoMigrationToRollBack) {
|
||||
@@ -103,6 +114,14 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("DownOne() after %d rollbacks error = %v", rolledBack, err)
|
||||
}
|
||||
if result.Version == assessmentBankMigrationVersion {
|
||||
// The bank migration removes its tables and functions and
|
||||
// leaves the policy table its openings referenced.
|
||||
assertTablesExist(ctx, t, pool, false, assessmentBankTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, false, assessmentBankFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, policyTableNames...)
|
||||
assessmentBankRolledBack = true
|
||||
}
|
||||
if result.Version == organizationMigrationVersion {
|
||||
// The organization migration removes its tables and its
|
||||
// function and leaves the identity tables they reference.
|
||||
@@ -155,10 +174,10 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if !identityRolledBack || !policyRolledBack || !consumerRolledBack || !deliveryRolledBack || !mailQuotaRolledBack ||
|
||||
!scheduledJobRolledBack || !organizationRolledBack {
|
||||
t.Fatalf("migrations %d, %d, %d, %d, %d, %d, and %d were not all rolled back",
|
||||
!scheduledJobRolledBack || !organizationRolledBack || !assessmentBankRolledBack {
|
||||
t.Fatalf("migrations %d, %d, %d, %d, %d, %d, %d, and %d were not all rolled back",
|
||||
identityMigrationVersion, policyMigrationVersion, consumerMigrationVersion, deliveryMigrationVersion, mailQuotaMigrationVersion,
|
||||
scheduledJobMigrationVersion, organizationMigrationVersion)
|
||||
scheduledJobMigrationVersion, organizationMigrationVersion, assessmentBankMigrationVersion)
|
||||
}
|
||||
assertTablesExist(ctx, t, pool, false, outboxTables...)
|
||||
assertTablesExist(ctx, t, pool, false, identityTableNames...)
|
||||
@@ -201,6 +220,8 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertTablesExist(ctx, t, pool, true, deliveryTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, organizationTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, organizationFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, assessmentBankTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, assessmentBankFunctionNames...)
|
||||
assertAllApplied(ctx, t, migrator, total)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user