Documentation ¶
Index ¶
- Variables
- func AddApplicationConstraint() *gormigrate.Migration
- func AddOrgIdToTenants() *gormigrate.Migration
- func AddResourceOwnershipToApplicationTypes() *gormigrate.Migration
- func AddRetryCounterToApplications() *gormigrate.Migration
- func AddTableUsers() *gormigrate.Migration
- func AddTenantsExternalTenantOrgIdUniqueIndex() *gormigrate.Migration
- func AddUserIdColumnIntoTables() *gormigrate.Migration
- func AvailabilityStatusColumnsNotNullConstraintDefaultValue() *gormigrate.Migration
- func InitialSchema() *gormigrate.Migration
- func MakeEmptyExternalTenantsOrgIdsNull() *gormigrate.Migration
- func Migrate(db *gorm.DB)
- func RemoveDuplicatedTenantIdsOrgIds() *gormigrate.Migration
- func RemoveOldMigrationsTable() *gormigrate.Migration
- func RemoveProcessedDuplicatedTenants() *gormigrate.Migration
- func RenameForeignKeysIndexes() *gormigrate.Migration
- func SourceTypesAddCategoryColumn() *gormigrate.Migration
- func TranslateEbsAccountNumbersToOrgIds() *gormigrate.Migration
Constants ¶
This section is empty.
Variables ¶
var MigrationsCollection = []*gormigrate.Migration{ InitialSchema(), AddOrgIdToTenants(), TranslateEbsAccountNumbersToOrgIds(), SourceTypesAddCategoryColumn(), AddRetryCounterToApplications(), AddTableUsers(), MakeEmptyExternalTenantsOrgIdsNull(), RemoveDuplicatedTenantIdsOrgIds(), AddTenantsExternalTenantOrgIdUniqueIndex(), AddUserIdColumnIntoTables(), AddResourceOwnershipToApplicationTypes(), AddApplicationConstraint(), RemoveOldMigrationsTable(), RenameForeignKeysIndexes(), RemoveProcessedDuplicatedTenants(), AvailabilityStatusColumnsNotNullConstraintDefaultValue(), }
Functions ¶
func AddApplicationConstraint ¶
func AddApplicationConstraint() *gormigrate.Migration
func AddOrgIdToTenants ¶
func AddOrgIdToTenants() *gormigrate.Migration
AddOrgIdToTenants creates a new "org_id" column with an index in the "tenants" table. It also adds a comment to the "external_tenant" column, clarifying that it refers to "EBS account numbers".
func AddResourceOwnershipToApplicationTypes ¶
func AddResourceOwnershipToApplicationTypes() *gormigrate.Migration
AddResourceOwnershipToApplicationTypes adds new column "resource_ownership" into table "application_types".
func AddRetryCounterToApplications ¶
func AddRetryCounterToApplications() *gormigrate.Migration
func AddTableUsers ¶
func AddTableUsers() *gormigrate.Migration
func AddTenantsExternalTenantOrgIdUniqueIndex ¶
func AddTenantsExternalTenantOrgIdUniqueIndex() *gormigrate.Migration
AddTenantsExternalTenantOrgIdUniqueIndex adds a unique index to the "external tenant" and "org id" columns to avoid a race condition that enabled having multiple rows of data sharing the same "external tenant" or "org id" values. This was caused by sending two parallel requests having a non-existent tenant on the database, which would create the two separate records containing the same values at the same time.
An index is created instead of a constraint because we are going to be searching by "external_tenant" and "org_id" columns, so we can benefit from that index.
func AddUserIdColumnIntoTables ¶
func AddUserIdColumnIntoTables() *gormigrate.Migration
AddUserIdColumnIntoTables adds into tables "sources", "applications", "authentications" and "application_authentications" a new column "user_id" and creates in each table a foreign key, e.g. "sources.user_id" -> "users.id".
func AvailabilityStatusColumnsNotNullConstraintDefaultValue ¶
func AvailabilityStatusColumnsNotNullConstraintDefaultValue() *gormigrate.Migration
AvailabilityStatusColumnsNotNullConstraintDefaultValue adds a NOT NULL constraint to the "availability_status" columns from all the tables that have it, and it also adds a default value "in_progress" for new insertions. The migration takes care of the NULL or empty values from those columns and sets them to "in_progress".
func InitialSchema ¶
func InitialSchema() *gormigrate.Migration
InitialSchema imports the legacy schema into the current database. If the current database already has the schema set up, the migration will be nearly a no-op.
func MakeEmptyExternalTenantsOrgIdsNull ¶
func MakeEmptyExternalTenantsOrgIdsNull() *gormigrate.Migration
MakeEmptyExternalTenantsOrgIdsNull makes all the empty "external_tenant" and "org_id" values NULL in the database.
func Migrate ¶
Migrate migrates the database schema to the latest version. Implements the single instance lock algorithm detailed in https://redis.io/topics/distlock#correct-implementation-with-a-single-instance. On error, it tries deleting the lock before exiting the program.
func RemoveDuplicatedTenantIdsOrgIds ¶
func RemoveDuplicatedTenantIdsOrgIds() *gormigrate.Migration
RemoveDuplicatedTenantIdsOrgIds fetches all the duplicated tenants, makes sure that they are indeed duplicated, and unifies all the subresources in a single tenant before deleting the duplicated one.
func RemoveOldMigrationsTable ¶
func RemoveOldMigrationsTable() *gormigrate.Migration
RemoveOldMigrationsTable removes the ActiveRecord migrations table.
func RemoveProcessedDuplicatedTenants ¶
func RemoveProcessedDuplicatedTenants() *gormigrate.Migration
RemoveProcessedDuplicatedTenants removes all the tenants that were marked as duplicates after running the migration "RemoveDuplicatedTenantIdsOrgIds" with ID "20220608090500". It makes sure to only remove the duplicated tenants that don't have any related objects in any of the other tables that have an FK to the tenants table.
func RenameForeignKeysIndexes ¶
func RenameForeignKeysIndexes() *gormigrate.Migration
RenameForeignKeysIndexes renames the foreign keys and indexes to what Postgres names them by default.
func SourceTypesAddCategoryColumn ¶
func SourceTypesAddCategoryColumn() *gormigrate.Migration
SourceTypesAddCategoryColumn adds a "category" column to the "source_types" table. The column will have a "not null" constraint, so for that the migration performs three steps inside the transaction:
1. Creates the column with the not null constraint and defaults it to "Cloud". 2. Loops through all the source types and updates them with their corresponding category name. 3. Removes the default value for the column.
func TranslateEbsAccountNumbersToOrgIds ¶
func TranslateEbsAccountNumbersToOrgIds() *gormigrate.Migration
TranslateEbsAccountNumbersToOrgIds attempts to translate the current EBS account numbers to "org_id"s.
If the translation is not possible, it doesn't fail the migration: it simply logs an error. This is due to the transition stage we are in. Since we are proactively taking steps towards the full "OrgId" support, not having a translation for an EBS account number is acceptable.
It also adds a comment to the "external_tenant" column, clarifying that it refers to "EBS account numbers".
Types ¶
This section is empty.
Source Files ¶
- 20220222111000_initial_schema.go
- 20220330120000_add_org_id_tenants.go
- 20220404150000_translate_ebs_org_ids.go
- 20220413120000_sources_add_category_column.go
- 20220428124100_add_retry_counter_to_applications.go
- 20220510112000_add_application_constraint.go
- 20220603140800_add_table_users.go
- 20220607140800_add_user_id_column.go
- 20220607215900_add_resource_ownership_column.go
- 20220608090000_make_empty_external_tenants_org_ids_null.go
- 20220608090500_remove_duplicated_tenant_ids_org_ids.go
- 20220608091000_add_tenants_external_tenant_org_id_unique_index.go
- 20220705100000_remove_old_migrations_table.go
- 20220705103000_rename_indexes_foreign_keys.go
- 20220830100000_remove_processed_duplicate_tenants.go
- 20220905120000_availability_status_not_null_constraint_default_value.go
- migrations.go