// Migrate updates the dashboards at runtime
775735
func (d *DashboardsStore) Migrate(ctx context.Context) error {
	// 1. Add UUIDs to cells without one
	boards, err := d.All(ctx)
	if err != nil {
		return err
	}
	if err := d.AddIDs(ctx, boards); err != nil {
		return nil
	}

	defaultOrg, err := d.client.OrganizationsStore.DefaultOrganization(ctx)
	if err != nil {
		return err
	}

	for _, board := range boards {
		if board.Organization == "" {
			board.Organization = defaultOrg.ID
			if err := d.Update(ctx, board); err != nil {
				return nil
			}
		}
	}

	return nil
}
623722
func Migrate(x *xorm.Engine) error {
	if err := x.Sync(new(Version)); err != nil {
		return fmt.Errorf("sync: %v", err)
	}

	currentVersion := &Version{ID: 1}
	has, err := x.Get(currentVersion)
	if err != nil {
		return fmt.Errorf("get: %v", err)
	} else if !has {
		// If the version record does not exist we think
		// it is a fresh installation and we can skip all migrations.
		currentVersion.ID = 0
		currentVersion.Version = int64(_MIN_DB_VER + len(migrations))

		if _, err = x.InsertOne(currentVersion); err != nil {
			return fmt.Errorf("insert: %v", err)
		}
	}

	v := currentVersion.Version
	if _MIN_DB_VER > v {
		log.Fatal(0, `
Hi there, thank you for using Gogs for so long!
However, Gogs has stopped supporting auto-migration from your previously installed version.
But the good news is, it's very easy to fix this problem!
You can migrate your older database using a previous release, then you can upgrade to the newest version.

Please save following instructions to somewhere and start working:

- If you were using below 0.6.0 (e.g. 0.5.x), download last supported archive from following link:
	https://github.com/gogs/gogs/releases/tag/v0.7.33
- If you were using below 0.7.0 (e.g. 0.6.x), download last supported archive from following link:
	https://github.com/gogs/gogs/releases/tag/v0.9.141

Once finished downloading,

1. Extract the archive and to upgrade steps as usual.
2. Run it once. To verify, you should see some migration traces.
3. Once it starts web server successfully, stop it.
4. Now it's time to put back the release archive you originally intent to upgrade.
5. Enjoy!

In case you're stilling getting this notice, go through instructions again until it disappears.`)
		return nil
	}

	if int(v-_MIN_DB_VER) > len(migrations) {
		// User downgraded Gogs.
		currentVersion.Version = int64(len(migrations) + _MIN_DB_VER)
		_, err = x.Id(1).Update(currentVersion)
		return err
	}
	for i, m := range migrations[v-_MIN_DB_VER:] {
		log.Info("Migration: %s", m.Description())
		if err = m.Migrate(x); err != nil {
			return fmt.Errorf("do migrate: %v", err)
		}
		currentVersion.Version = v + int64(i) + 1
		if _, err = x.Id(1).Update(currentVersion); err != nil {
			return err
		}
	}
	return nil
}
82690
func migrate(rootDir string, b *Backend) error {
	// Check if the directory structure is the old bucket format.
	ok, err := isOld(rootDir)
	if err != nil {
		return trace.Wrap(err)
	}
	// Found the new flat keyspace directory backend, nothing to do.
	if !ok {
		b.log.Debugf("Found new flat keyspace, skipping migration.")
		return nil
	}

	// The old directory backend was found, make a backup in-case is needs to
	// be restored.
	backupDir := rootDir + ".backup-" + time.Now().Format(time.RFC3339)
	err = os.Rename(rootDir, backupDir)
	if err != nil {
		return trace.Wrap(err)
	}
	err = os.MkdirAll(rootDir, defaultDirMode)
	if err != nil {
		return trace.ConvertSystemError(err)
	}

	b.log.Infof("Migrating directory backend to new flat keyspace. Backup in %v.", backupDir)

	// Go over every file in the backend. If the key is not expired upsert
	// into the new backend.
	err = filepath.Walk(backupDir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return trace.ConvertSystemError(err)
		}

		// Skip the locks directory completely.
		if info.IsDir() && info.Name() == ".locks" {
			return filepath.SkipDir
		}
		// Skip over directories themselves, but not their content.
		if info.IsDir() {
			return nil
		}
		// Skip over TTL files (they are handled by readTTL function).
		if strings.HasPrefix(info.Name(), ".") {
			return nil
		}

		// Construct key and flat bucket.
		key := info.Name()
		flatbucket := strings.TrimPrefix(path, backupDir)
		flatbucket = strings.TrimSuffix(flatbucket, string(filepath.Separator)+key)

		// Read in TTL for key. If the key is expired, skip over it.
		ttl, expired, err := readTTL(backupDir, flatbucket, key)
		if err != nil {
			return trace.Wrap(err)
		}
		if expired {
			b.log.Infof("Skipping migration of expired bucket %q and key %q.", flatbucket, info.Name())
			return nil
		}

		// Read in the value of the key.
		value, err := ioutil.ReadFile(path)
		if err != nil {
			return trace.Wrap(err)
		}

		// Upsert key and value (with TTL) into new flat keyspace backend.
		bucket := strings.Split(flatbucket, string(filepath.Separator))
		err = b.UpsertVal(bucket, key, value, ttl)
		if err != nil {
			return trace.Wrap(err)
		}
		b.log.Infof("Migrated bucket %q and key %q with TTL %v.", flatbucket, key, ttl)

		return nil
	})
	if err != nil {
		return trace.Wrap(err)
	}

	b.log.Infof("Migration successful.")
	return nil
}
1121830
func (s *DB) AutoMigrate(values ...interface{}) *DB {
	db := s.Unscoped()
	for _, value := range values {
		db = db.NewScope(value).autoMigrate().db
	}
	return db
}
706407
func (w *WorkflowTypeMigrator) Migrate() {
	for _, dd := range w.DeprecatedWorkflowTypes {
		if w.isDeprecated(dd.Domain, dd.WorkflowType.Name, dd.WorkflowType.Version) {
			Log.Printf("action=migrate at=deprecate-workflow domain=%s workflow=%s version=%s status=previously-deprecated", LS(dd.Domain), LS(dd.WorkflowType.Name), LS(dd.WorkflowType.Version))
		} else {
			w.deprecate(dd)
			Log.Printf("action=migrate at=deprecate-workflow domain=%s  workflow=%s version=%s status=deprecate", LS(dd.Domain), LS(dd.WorkflowType.Name), LS(dd.WorkflowType.Version))
		}
	}
	for _, r := range w.RegisteredWorkflowTypes {
		if w.isRegisteredNotDeprecated(r) {
			Log.Printf("action=migrate at=register-workflow domain=%s workflow=%s version=%s status=previously-registered", LS(r.Domain), LS(r.Name), LS(r.Version))
		} else {
			w.register(r)
			Log.Printf("action=migrate at=register-workflow domain=%s  workflow=%s version=%s status=registered", LS(r.Domain), LS(r.Name), LS(r.Version))
		}
	}
}
108859
func migrate(args []string, r *githistory.Rewriter, l *tasklog.Logger, opts *githistory.RewriteOptions) {
	requireInRepo()

	opts, err := rewriteOptions(args, opts, l)
	if err != nil {
		ExitWithError(err)
	}

	_, err = r.Rewrite(opts)
	if err != nil {
		ExitWithError(err)
	}
}
1275981
func (c *Client) MigrateVirtualMachine(p *MigrateVirtualMachineParameter) (*VirtualMachine, error) {
	obj, err := c.Request("migrateVirtualMachine", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*VirtualMachine), err
}
576360
func MigrateWALs(ctx context.Context, oldDir, newDir string, oldFactory, newFactory WALFactory, snapshot walpb.Snapshot) error {
	oldReader, waldata, err := ReadRepairWAL(ctx, oldDir, snapshot, oldFactory)
	if err != nil {
		return err
	}
	oldReader.Close()

	if err := os.MkdirAll(filepath.Dir(newDir), 0700); err != nil {
		return errors.Wrap(err, "could not create parent directory")
	}

	// keep temporary wal directory so WAL initialization appears atomic
	tmpdirpath := filepath.Clean(newDir) + ".tmp"
	if err := os.RemoveAll(tmpdirpath); err != nil {
		return errors.Wrap(err, "could not remove temporary WAL directory")
	}
	defer os.RemoveAll(tmpdirpath)

	tmpWAL, err := newFactory.Create(tmpdirpath, waldata.Metadata)
	if err != nil {
		return errors.Wrap(err, "could not create new WAL in temporary WAL directory")
	}
	defer tmpWAL.Close()

	if err := tmpWAL.SaveSnapshot(snapshot); err != nil {
		return errors.Wrap(err, "could not write WAL snapshot in temporary directory")
	}

	if err := tmpWAL.Save(waldata.HardState, waldata.Entries); err != nil {
		return errors.Wrap(err, "could not migrate WALs to temporary directory")
	}
	if err := tmpWAL.Close(); err != nil {
		return err
	}

	return os.Rename(tmpdirpath, newDir)
}
1225664
func MigrateRollback(currpath, driver, connStr, dir string) {
	migrate("rollback", currpath, driver, connStr, dir)
}
445748
func ApplicationMigrations(prefix string) map[string]storage.MigrateFunction {
	funcs := make(map[string]storage.MigrateFunction)
	for v, f := range applicationMigrations {
		funcs[v] = f(prefix)
	}
	return funcs
}
982995
func (pb *Publish) AutoMigrate(values ...interface{}) {
	for _, value := range values {
		tableName := pb.DB.NewScope(value).TableName()
		pb.DraftDB().Table(DraftTableName(tableName)).AutoMigrate(value)
	}
}
897995
func (u DashboardUpdate) Apply(d *Dashboard) error {
	if u.Name != nil {
		d.Name = *u.Name
	}

	if u.Description != nil {
		d.Description = *u.Description
	}

	return nil
}
946002
func (d *DashboardsStore) Update(ctx context.Context, dash chronograf.Dashboard) error {
	if err := d.client.db.Update(func(tx *bolt.Tx) error {
		// Get an existing dashboard with the same ID.
		b := tx.Bucket(DashboardsBucket)
		strID := strconv.Itoa(int(dash.ID))
		if v := b.Get([]byte(strID)); v == nil {
			return chronograf.ErrDashboardNotFound
		}

		for i, cell := range dash.Cells {
			if cell.ID != "" {
				continue
			}
			cid, err := d.IDs.Generate()
			if err != nil {
				return err
			}
			cell.ID = cid
			dash.Cells[i] = cell
		}
		if v, err := internal.MarshalDashboard(dash); err != nil {
			return err
		} else if err := b.Put([]byte(strID), v); err != nil {
			return err
		}
		return nil
	}); err != nil {
		return err
	}

	return nil
}
11835
func (_m *FacadeInterface) MigrateServices(ctx datastore.Context, request dao.ServiceMigrationRequest) error {
	ret := _m.Called(ctx, request)

	var r0 error
	if rf, ok := ret.Get(0).(func(datastore.Context, dao.ServiceMigrationRequest) error); ok {
		r0 = rf(ctx, request)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1112268
func migrate(name string, port uint64, peerListenUrls string, peerAdvertiseUrls string, binPath string, dataDirPath string, etcdDataPrefix string, ttlKeysDirectory string,
	initialCluster string, target *EtcdVersionPair, bundledVersions SupportedVersions, etcdServerArgs string) {

	dataDir, err := OpenOrCreateDataDirectory(dataDirPath)
	if err != nil {
		klog.Errorf("Error opening or creating data directory %s: %v", dataDirPath, err)
		os.Exit(1)
	}

	cfg := &EtcdMigrateCfg{
		binPath:           binPath,
		name:              name,
		port:              port,
		peerListenUrls:    peerListenUrls,
		peerAdvertiseUrls: peerAdvertiseUrls,
		etcdDataPrefix:    etcdDataPrefix,
		ttlKeysDirectory:  ttlKeysDirectory,
		initialCluster:    initialCluster,
		supportedVersions: bundledVersions,
		dataDirectory:     dataDirPath,
		etcdServerArgs:    etcdServerArgs,
	}
	client, err := NewEtcdMigrateClient(cfg)
	if err != nil {
		klog.Errorf("Migration failed: %v", err)
		os.Exit(1)
	}
	defer client.Close()

	migrator := &Migrator{cfg, dataDir, client}

	err = migrator.MigrateIfNeeded(target)
	if err != nil {
		klog.Errorf("Migration failed: %v", err)
		os.Exit(1)
	}
}
80221
func RunMigrations(cfg abcconfig.DBConfig, migrationsPath string) (int, error) {
	connStr, err := GetConnStr(cfg)
	if err != nil {
		return 0, err
	}

	count, err := mig.Up(cfg.DB, connStr, migrationsPath)
	if err != nil {
		return count, err
	}

	return count, nil
}
18331
func (m *Migrator) Migrate() error {
	for _, migration := range m.Migrations(Inactive) {
		if err := m.ApplyMigration(migration, upMigration); err != nil {
			return err
		}
	}
	return nil
}