Files
grafana/pkg/services/sqlstore/migrations/cloud_migrations.go
Leonard Gram 383ebb2bc4 Cloudmigration: create migration (#85386)
* Cloudmigration: create migration

* fix drone build

* lint fix

* fix unit test

---------

Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com>
2024-03-29 01:55:27 +01:00

41 lines
1.7 KiB
Go

package migrations
import (
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func addCloudMigrationsMigrations(mg *Migrator) {
migrationTable := Table{
Name: "cloud_migration",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "auth_token", Type: DB_Text, Nullable: true}, // encrypted
{Name: "stack", Type: DB_Text},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
},
}
migrationRunTable := Table{
Name: "cloud_migration_run",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "cloud_migration_uid", Type: DB_NVarchar, Length: 40, Nullable: true}, // get from the cloud service
{Name: "result", Type: DB_Text, Nullable: false},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
{Name: "finished", Type: DB_DateTime, Nullable: true},
},
}
mg.AddMigration("create cloud_migration table v1", NewAddTableMigration(migrationTable))
mg.AddMigration("create cloud_migration_run table v1", NewAddTableMigration(migrationRunTable))
stackIDColumn := Column{Name: "stack_id", Type: DB_BigInt, Nullable: false}
regionSlugColumn := Column{Name: "region_slug", Type: DB_Text, Nullable: false}
clusterSlugColumn := Column{Name: "cluster_slug", Type: DB_Text, Nullable: false}
mg.AddMigration("add stack_id column", NewAddColumnMigration(migrationTable, &stackIDColumn))
mg.AddMigration("add region_slug column", NewAddColumnMigration(migrationTable, &regionSlugColumn))
mg.AddMigration("add cluster_slug column", NewAddColumnMigration(migrationTable, &clusterSlugColumn))
}