How to use Info method of migrator Package

Best Testkube code snippet using migrator.Info

migrate.go

Source:migrate.go Github

copy

Full Screen

...71 return72 }73 mContainer.Lock()74 mContainer.state = MigrateCompleted75 logger.INFO("[#cluster] migrator container %s > %s to %s", ShortContainerID(mContainer.ID), ShortContainerID(container.Info.ID), engine.IP)76 mContainer.Unlock()77 return78}79// Migrator is exported80type Migrator struct {81 sync.RWMutex82 MetaID string83 Cluster *Cluster84 retryCount int6485 migrateDelay time.Duration86 containers []*MigrateContainer87 handler MigratorHandler88}89// NewMigrator is exported90func NewMigrator(metaid string, containers Containers, cluster *Cluster, migrateDelay time.Duration, handler MigratorHandler) *Migrator {91 mContainers := []*MigrateContainer{}92 for _, container := range containers {93 mContainer := NewMigrateContainer(container.Info.ID, container.BaseConfig)94 if mContainer != nil {95 mContainers = append(mContainers, mContainer)96 }97 }98 return &Migrator{99 MetaID: metaid,100 Cluster: cluster,101 retryCount: cluster.createRetry,102 migrateDelay: migrateDelay,103 containers: mContainers,104 handler: handler,105 }106}107func (migrator *Migrator) verifyEngines() bool {108 _, engines, err := migrator.Cluster.GetMetaDataEngines(migrator.MetaID)109 if err != nil {110 return false111 }112 for _, engine := range engines {113 if engine.IsHealthy() {114 return true115 }116 }117 return false118}119func (migrator *Migrator) isAllCompleted() bool {120 migrator.RLock()121 defer migrator.RUnlock()122 for _, mContainer := range migrator.containers {123 if mContainer.GetState() != MigrateCompleted {124 return false125 }126 }127 return true128}129func (migrator *Migrator) isPartCompleted() bool {130 migrator.RLock()131 defer migrator.RUnlock()132 nCompletedCount := 0133 for _, mContainer := range migrator.containers {134 if mContainer.GetState() == MigrateCompleted {135 nCompletedCount = nCompletedCount + 1136 }137 }138 if nCompletedCount == 0 {139 return false140 }141 return nCompletedCount != len(migrator.containers)142}143func (migrator *Migrator) resetMigrateContainers() {144 migrator.Lock()145 for _, mContainer := range migrator.containers {146 if mContainer.GetState() == MigrateFailure {147 mContainer.SetState(MigrateReady)148 }149 }150 migrator.retryCount = migrator.retryCount - 1151 migrator.Unlock()152}153func (migrator *Migrator) selectMigrateContainer() *MigrateContainer {154 migrator.RLock()155 defer migrator.RUnlock()156 for _, mContainer := range migrator.containers {157 if mContainer.GetState() == MigrateReady {158 return mContainer159 }160 }161 return nil162}163func (migrator *Migrator) removeMigrateContainer(mContainer *MigrateContainer) {164 migrator.Lock()165 for i, pmContainer := range migrator.containers {166 if pmContainer == mContainer {167 migrator.containers = append(migrator.containers[:i], migrator.containers[i+1:]...)168 break169 }170 }171 migrator.Unlock()172}173func (migrator *Migrator) clearMigrateContainers() {174 migrator.Lock()175 migrator.containers = []*MigrateContainer{}176 migrator.Unlock()177}178// Containers is exported179func (migrator *Migrator) Containers() []*MigrateContainer {180 migrator.RLock()181 mContainers := []*MigrateContainer{}182 for _, mContainer := range migrator.containers {183 mContainers = append(mContainers, mContainer)184 }185 migrator.RUnlock()186 return mContainers187}188// Container is exported189func (migrator *Migrator) Container(containerid string) *MigrateContainer {190 migrator.RLock()191 defer migrator.RUnlock()192 for _, mContainer := range migrator.containers {193 if mContainer.ID == containerid {194 return mContainer195 }196 }197 return nil198}199// Start is exported200func (migrator *Migrator) Start() {201 time.Sleep(migrator.migrateDelay)202 for {203 migrator.RLock()204 mContainers := migrator.containers205 migrator.RUnlock()206 if len(mContainers) == 0 {207 break208 }209 if !migrator.isAllCompleted() {210 if !migrator.verifyEngines() {211 err := fmt.Errorf("cluster no docker-engine available")212 logger.ERROR("[#cluster] migrator %s containers error %s.", migrator.MetaID, err)213 migrator.clearMigrateContainers()214 migrator.Cluster.configCache.ClearContainerBaseConfig(migrator.MetaID)215 migrator.handler.OnMigratorNotifyHandleFunc(migrator, err)216 break217 }218 }219 mContainer := migrator.selectMigrateContainer()220 if mContainer != nil {221 mContainer.Execute(migrator.Cluster)222 if mContainer.GetState() == MigrateCompleted {223 migrator.Cluster.configCache.RemoveContainerBaseConfig(migrator.MetaID, mContainer.ID)224 }225 continue226 }227 if migrator.isAllCompleted() {228 migrator.handler.OnMigratorNotifyHandleFunc(migrator, nil)229 break230 }231 if migrator.retryCount <= 0 {232 migrator.Lock()233 for _, mContainer := range migrator.containers {234 if mContainer.GetState() == MigrateFailure {235 migrator.Cluster.configCache.RemoveContainerBaseConfig(migrator.MetaID, mContainer.ID)236 }237 }238 migrator.Unlock()239 migrator.handler.OnMigratorNotifyHandleFunc(migrator, fmt.Errorf("meta containers part migrated failure."))240 break241 }242 if migrator.isPartCompleted() {243 migrator.handler.OnMigratorNotifyHandleFunc(migrator, fmt.Errorf("meta containers part migrated completed."))244 }245 migrator.resetMigrateContainers()246 continue247 }248 migrator.clearMigrateContainers()249 migrator.handler.OnMigratorQuitHandleFunc(migrator)250}251// Update is exported252func (migrator *Migrator) Update(metaid string, containers Containers) {253 for _, container := range containers {254 if mContainer := migrator.Container(container.Info.ID); mContainer == nil {255 mContainer = NewMigrateContainer(container.Info.ID, container.BaseConfig)256 if mContainer != nil {257 migrator.Lock()258 migrator.containers = append(migrator.containers, mContainer)259 migrator.Unlock()260 }261 }262 }263}264// Cancel is exported265func (migrator *Migrator) Cancel(metaid string, containers Containers) {266 for _, container := range containers {267 if mContainer := migrator.Container(container.Info.ID); mContainer != nil {268 state := mContainer.GetState()269 if state == MigrateReady || state == MigrateFailure {270 migrator.removeMigrateContainer(mContainer)271 }272 }273 }274}275// Clear is exported276func (migrator *Migrator) Clear() {277 migrator.Lock()278 migrator.containers = []*MigrateContainer{}279 migrator.Unlock()280}281// MigratorHandler is exported...

Full Screen

Full Screen

migrator.go

Source:migrator.go Github

copy

Full Screen

...47 ran = true48 }49 }50 if !ran {51 console.Info("Nothing to migrate.")52 }53}54func (migrator *Migrator) Rollback() {55 lastMigration := Migration{}56 migrator.DB.Order("id DESC").First(&lastMigration)57 var migrations []Migration58 migrator.DB.Where("batch = ?", lastMigration.Batch).Order("id DESC").Find(&migrations)59 if !migrator.rollbackMigrations(migrations) {60 console.Info("Nothing to rollback.")61 }62}63func (migrator *Migrator) rollbackMigrations(migrations []Migration) bool {64 ran := false65 for _, _migration := range migrations {66 fmt.Printf("%s %s\n", ansi.Color("Rolling back:", "yellow"), _migration.Migration)67 migrationFile := GetMigrationFile(_migration.Migration)68 if migrationFile.Down != nil {69 migrationFile.Down(migrator.DB.Migrator())70 }71 ran = true72 migrator.DB.Delete(&_migration)73 fmt.Printf("%s %s\n", ansi.Color("Rolled back:", "green"), migrationFile.FileName)74 }75 return ran76}77func (migrator *Migrator) getBatch() int {78 batch := 179 lastMigration := Migration{}80 migrator.DB.Order("id DESC").First(&lastMigration)81 if lastMigration.ID > 0 {82 batch = lastMigration.Batch + 183 }84 return batch85}86func (migrator *Migrator) readAllMigrationFiles() []MigrationFile {87 files, err := ioutil.ReadDir(migrator.Folder)88 console.ExitIf(err)89 var migrateFiles []MigrationFile90 for _, f := range files {91 // Get filename92 fileName := file.GetFileNameWithoutExtension(f.Name())93 migrationFile := GetMigrationFile(fileName)94 if len(migrationFile.FileName) > 0 {95 migrateFiles = append(migrateFiles, migrationFile)96 }97 }98 return migrateFiles99}100func (migrator *Migrator) runUpMigration(migrationFile MigrationFile, batch int) {101 if migrationFile.Up != nil {102 fmt.Printf("%s %s\n", ansi.Color("Migrating:", "yellow"), migrationFile.FileName)103 migrationFile.Up(migrator.DB.Migrator())104 fmt.Printf("%s %s\n", ansi.Color("Migrated:", "green"), migrationFile.FileName)105 }106 err := migrator.DB.Create(&Migration{Migration: migrationFile.FileName, Batch: batch}).Error107 console.ExitIf(err)108}109func (migrator *Migrator) Reset() {110 var migrations []Migration111 migrator.DB.Order("id DESC").Find(&migrations)112 if !migrator.rollbackMigrations(migrations) {113 console.Info("Nothing to rollback.")114 }115}116func (migrator *Migrator) Refresh() {117 migrator.Reset()118 migrator.Up()119}120func (migrator *Migrator) Fresh() {121 // Delete all tables122 database.DB = migrator.DB123 err := database.DeleteAllTables()124 console.ExitIf(err)125 console.Info("Dropped all tables successfully.")126 // Migrate127 migrator.createMigrationsTable()128 console.Info("Migration table created successfully.")129 migrator.Up()130}131func isNotMigrated(migrations []Migration, migrationFile MigrationFile) bool {132 for _, migration := range migrations {133 if migration.Migration == migrationFile.FileName {134 return false135 }136 }137 return true138}...

Full Screen

Full Screen

migrations.go

Source:migrations.go Github

copy

Full Screen

...40 }41 if target == 0 {42 target = int32(len(migrator.Migrations))43 }44 log.Info("migration started",45 log.Int32("current-version", version),46 log.Int("last-version", len(migrator.Migrations)),47 log.Int32("target-version", target))48 migrator.OnStart = func(v int32, name, direction, sql string) {49 log.Info("migrating", log.Int32("version", v), log.String("name", name), log.String("direction", direction))50 }51 err = migrator.MigrateTo(ctx, target)52 if err != nil {53 log.Error(err)54 return err55 }56 version, err = migrator.GetCurrentVersion(ctx)57 if err != nil {58 log.Error(err)59 return err60 }61 log.Info("migration finished", log.Int32("current-version", version))62 return nil63}64type migratorFS struct {65 embed.FS66}67func (m migratorFS) ReadDir(dirname string) ([]os.FileInfo, error) {68 entries, err := m.FS.ReadDir(dirname)69 if err != nil {70 return nil, err71 }72 infos := []os.FileInfo{}73 for _, entry := range entries {74 info, err := entry.Info()75 if err != nil {76 return nil, err77 }78 infos = append(infos, info)79 }80 return infos, nil81}82func (m migratorFS) ReadFile(filename string) ([]byte, error) {83 return m.FS.ReadFile(filename)84}85func (m migratorFS) Glob(pattern string) ([]string, error) {86 pattern = filepath.Base(pattern)87 matches := []string{}88 entries, err := m.FS.ReadDir(".")...

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 orm.RegisterDriver("mysql", orm.DRMySQL)4 orm.RegisterDataBase("default", "mysql", "root:root@/test?charset=utf8")5 orm.RunSyncdb("default", false, true)6 o := orm.NewOrm()7 migrator := orm.NewMigrator()8 migrator.Info()9 migrator.DropColumn("users", "email")10 migrator.Info()11 migrator.AddColumn("users", "email")12 migrator.Info()13 migrator.RenameColumn("users", "email", "new_email")14 migrator.Info()15 migrator.RenameTable("users", "new_users")16 migrator.Info()17 migrator.AlterColumn("new_users", "new_email", "varchar(100)")18 migrator.Info()19 migrator.AlterColumn("new_users", "new_email", "varchar(100) null")20 migrator.Info()21 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test'")22 migrator.Info()23 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test' unique")24 migrator.Info()25 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test' unique comment 'test'")26 migrator.Info()27 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test' unique comment 'test' after id")28 migrator.Info()29 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test' unique comment 'test' after id")30 migrator.Info()31 migrator.AlterColumn("new_users", "new_email", "varchar(100) null default 'test

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2type Migrator struct {3}4func NewMigrator() *Migrator {5 return &Migrator{}6}7func (m Migrator) Info() {8 rows, err := m.DB.Query("SELECT version FROM schema_version")9 if err != nil {10 log.Fatal(err)11 }12 defer rows.Close()13 for rows.Next() {14 if err := rows.Scan(&version); err != nil {15 log.Fatal(err)16 }17 fmt.Println(version)18 }19 if err := rows.Err(); err != nil {20 log.Fatal(err)21 }22}23func (m Migrator) Migrate() {24 rows, err := m.DB.Query("SELECT version FROM schema_version")25 if err != nil {26 log.Fatal(err)27 }28 defer rows.Close()29 for rows.Next() {30 if err := rows.Scan(&version); err != nil {31 log.Fatal(err)32 }33 fmt.Println(version)34 }35 if err := rows.Err(); err != nil {36 log.Fatal(err)37 }38}39func (m Migrator) Rollback() {40 rows, err := m.DB.Query("SELECT version FROM schema_version")41 if err != nil {42 log.Fatal(err)43 }44 defer rows.Close()45 for rows.Next() {46 if err := rows.Scan(&version); err != nil {47 log.Fatal(err)48 }49 fmt.Println(version)50 }51 if err := rows.Err(); err != nil {52 log.Fatal(err)

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := migrator.Migrator{}4 m.Info()5 fmt.Println("Hello world")6}7import (8type Migrator struct {9}10func (m Migrator) Info() {11 fmt.Println("Migrator version 1.0")12}13If you want to run the above code from the root folder then you need to change the import path to14import "github.com/username/projectname/migrator"15If you want to run the above command from the root folder of the project then you need to change the import path to16import "github.com/username/projectname/migrator"

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful