0
0

More than 1 year has passed since last update.

Atlas APIにおけるMigrationモード

Last updated at Posted at 2022-10-24

どういう違いがあるのか、ドキュメントに書かれていないように見えたがコードを見ると書いてあった。

// Mode to compute the current state.
type Mode uint

const (
	// ModeReplay computes the current state by replaying the migration directory on the connected database.
	ModeReplay = iota
	// ModeInspect computes the current state by inspecting the connected database.
	ModeInspect
)

ModeReplay は生成されたマイグレーションのDDLから差分を計算してして新しいマイグレーションを生成するが、一方で ModeInspect はマイグレーション対象のデータベースのスキーマを参照してその差分からマイグレーションを計算し生成するみたい。

WithMigrationMode メソッドに書かれているコードコメントによると現時点では ModeInspect がデフォルトだが、長期的にはこちらがDeprecatedされ ModeReplay がデフォルトの挙動になるとのこと。

// WithMigrationMode instructs atlas how to compute the current state of the schema. This can be done by either
// replaying (ModeReplay) the migration directory on the connected database, or by inspecting (ModeInspect) the
// connection. Currently, ModeReplay is opt-in, and ModeInspect is the default. In future versions, ModeReplay will
// become the default behavior. This option has no effect when using online migrations.
func WithMigrationMode(mode Mode) MigrateOption {
	return func(a *Atlas) {
		a.mode = mode
	}
}

Versioned Migrationのドキュメントによると ModeInspect だと差分を生成するのに本番DBに繋ぎに行くことになるから微妙で、それならコードから一意に判定できる ModeReplay のほうがいいよね、ということらしい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0