Documentation ¶
Overview ¶
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2023 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func GetTenantDbs(ctx context.Context, client *mongo.Client, matcher store.TenantDbMatchFunc) ([]string, error)
- func IsErrNeedsMigration(e error) bool
- func UpdateMigrationInfo(ctx context.Context, version Version, sess *mongo.Client, db string) error
- func VersionIsLess(left Version, right Version) bool
- type DummyMigrator
- type Migration
- type MigrationEntry
- type Migrator
- type SimpleMigrator
- type Version
Constants ¶
const (
DbMigrationsColl = "migration_info"
)
this is a small internal data layer for the migration utils, may be shared by diff migrators
Variables ¶
var (
ErrNeedsMigration = "db needs migration"
)
Functions ¶
func GetTenantDbs ¶
func IsErrNeedsMigration ¶
func UpdateMigrationInfo ¶
UpdateMigrationInfo inserts a migration entry in the migration info collection.
func VersionIsLess ¶
Types ¶
type DummyMigrator ¶
MigratorDummy does not actually apply migrations, just inserts the target version into the db to mark the initial/current state.
type Migration ¶
Migration defines an incremental mongo migration step, with a concrete version. Current version of DB is passed as `from` parameter. Once migration completes, DB will be in version Version().
type MigrationEntry ¶
type MigrationEntry struct { Version Version `bson:"version"` Timestamp time.Time `bson:"timestamp"` }
func GetMigrationInfo ¶
GetMigrationInfo retrieves a list of migrations applied to the db. On success the function returns the MigrationEntries present in the db sorted by the version in decending order.
type Migrator ¶
type Migrator interface {
Apply(ctx context.Context, target Version, migrations []Migration) error
}
Migrator applies a list of migrations to bring the db up to target version.
type SimpleMigrator ¶
SimpleMigratior applies migrations by comparing `Version` of migrations passed to Apply() and already applied migrations. Only migrations that are of version higher than the last applied migration will be run. For example:
already applied migrations: 1.0.0, 1.0.1, 1.0.2 migrations in Apply(): 1.0.1, 1.0.3, 1.1.0 migrations that will be applied: 1.0.3, 1.1.0
func (*SimpleMigrator) Apply ¶
Apply will apply migrations, provided that Automigrate is on. After each successful migration a new migration record will be added to DB with the version of migration that was just applied. If a migration fails, Apply() returns an error and does not add a migration record (so last migration that is recorded is N-1).
Apply() will log some messages when running. Logger will be extracted from context using go-lib-micro/log.LoggerContextKey as key. If Automigrate is off, the migrator will just check if the DB is up-to-date, and return with ErrNeedsMigration otherwise. Check for it with IsErrNeedsMigration.