migrations

package
v0.0.0-...-f47fe49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func Migrate(db *gorm.DB)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL