feat(org): add organization and membership contract and storage
This commit is contained in:
1 parent
a0551a34b8
commit
bdc5855001
90 files changed
+17545
-480
No files matched your search
@@ -33,10 +33,14 @@ const (
|
||||
mailQuotaMigrationVersion = 7
|
||||
// scheduledJobMigrationVersion creates scheduledJobTableNames.
|
||||
scheduledJobMigrationVersion = 8
|
||||
// organizationMigrationVersion creates organizationTableNames and
|
||||
// organizationFunctionNames.
|
||||
organizationMigrationVersion = 10
|
||||
)
|
||||
|
||||
var (
|
||||
// Tables created by 00001, 00002, 00003, 00005, 00006, 00007, and 00008.
|
||||
// Tables created by 00001, 00002, 00003, 00005, 00006, 00007, 00008, and
|
||||
// 00010.
|
||||
outboxTables = []string{"outbox_events"}
|
||||
identityTableNames = []string{"users", "email_tokens", "sessions"}
|
||||
policyTableNames = []string{"policy_versions"}
|
||||
@@ -44,9 +48,12 @@ var (
|
||||
deliveryTableNames = []string{"mail_requests", "deliveries", "delivery_attempts"}
|
||||
mailQuotaTableNames = []string{"mail_quota_usage", "mail_quota_reservations"}
|
||||
scheduledJobTableNames = []string{"scheduled_jobs"}
|
||||
// Trigger functions created by 00003 and 00006.
|
||||
policyFunctionNames = []string{"policy_versions_refuse_change()", "policy_versions_stamp_creation()"}
|
||||
deliveryFunctionNames = []string{"deliveries_refuse_content_change()", "delivery_attempts_refuse_update()"}
|
||||
// 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()"}
|
||||
)
|
||||
|
||||
func TestPostgresMigrations(t *testing.T) {
|
||||
@@ -80,9 +87,11 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertFunctionsExist(ctx, t, pool, true, deliveryFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, mailQuotaTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, scheduledJobTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, organizationTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, organizationFunctionNames...)
|
||||
|
||||
identityRolledBack, policyRolledBack, consumerRolledBack, deliveryRolledBack, mailQuotaRolledBack := false, false, false, false, false
|
||||
scheduledJobRolledBack := false
|
||||
scheduledJobRolledBack, organizationRolledBack := false, false
|
||||
for rolledBack := 0; ; rolledBack++ {
|
||||
result, err := migrator.DownOne(ctx)
|
||||
if errors.Is(err, postgresadapter.ErrNoMigrationToRollBack) {
|
||||
@@ -94,6 +103,14 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("DownOne() after %d rollbacks error = %v", rolledBack, err)
|
||||
}
|
||||
if result.Version == organizationMigrationVersion {
|
||||
// The organization migration removes its tables and its
|
||||
// function and leaves the identity tables they reference.
|
||||
assertTablesExist(ctx, t, pool, false, organizationTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, false, organizationFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, identityTableNames...)
|
||||
organizationRolledBack = true
|
||||
}
|
||||
if result.Version == scheduledJobMigrationVersion {
|
||||
// The scheduled job migration removes only its own table.
|
||||
assertTablesExist(ctx, t, pool, false, scheduledJobTableNames...)
|
||||
@@ -137,10 +154,11 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
identityRolledBack = true
|
||||
}
|
||||
}
|
||||
if !identityRolledBack || !policyRolledBack || !consumerRolledBack || !deliveryRolledBack || !mailQuotaRolledBack || !scheduledJobRolledBack {
|
||||
t.Fatalf("migrations %d, %d, %d, %d, %d, and %d were not all rolled back",
|
||||
if !identityRolledBack || !policyRolledBack || !consumerRolledBack || !deliveryRolledBack || !mailQuotaRolledBack ||
|
||||
!scheduledJobRolledBack || !organizationRolledBack {
|
||||
t.Fatalf("migrations %d, %d, %d, %d, %d, %d, and %d were not all rolled back",
|
||||
identityMigrationVersion, policyMigrationVersion, consumerMigrationVersion, deliveryMigrationVersion, mailQuotaMigrationVersion,
|
||||
scheduledJobMigrationVersion)
|
||||
scheduledJobMigrationVersion, organizationMigrationVersion)
|
||||
}
|
||||
assertTablesExist(ctx, t, pool, false, outboxTables...)
|
||||
assertTablesExist(ctx, t, pool, false, identityTableNames...)
|
||||
@@ -181,6 +199,8 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertFunctionsExist(ctx, t, pool, true, policyFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, consumerTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, deliveryTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, organizationTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, organizationFunctionNames...)
|
||||
assertAllApplied(ctx, t, migrator, total)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user