From 8e6fb9fe60ee60bd72bdb14342509c50587d811e Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 12 Feb 2025 11:08:17 -0500 Subject: [PATCH 1/2] disable auto migration (#866) --- cmd/zrok/adminMigrate.go | 5 +++++ controller/store/frontend.go | 21 ++++++++++++++------- controller/store/store.go | 13 ++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cmd/zrok/adminMigrate.go b/cmd/zrok/adminMigrate.go index d900b728..c58871e2 100644 --- a/cmd/zrok/adminMigrate.go +++ b/cmd/zrok/adminMigrate.go @@ -33,7 +33,12 @@ func (cmd *adminMigrate) run(_ *cobra.Command, args []string) { if err != nil { panic(err) } + logrus.Info(cf.Dump(inCfg, cf.DefaultOptions())) + + // override the 'disable_auto_migration' setting... the user is requesting a migration here. + inCfg.Store.DisableAutoMigration = false + if _, err := store.Open(inCfg.Store); err != nil { panic(err) } diff --git a/controller/store/frontend.go b/controller/store/frontend.go index 8086b468..20ce8834 100644 --- a/controller/store/frontend.go +++ b/controller/store/frontend.go @@ -42,39 +42,44 @@ func (str *Store) CreateGlobalFrontend(f *Frontend, tx *sqlx.Tx) (int, error) { } func (str *Store) GetFrontend(id int, tx *sqlx.Tx) (*Frontend, error) { + utrx := tx.Unsafe() i := &Frontend{} - if err := tx.QueryRowx("select * from frontends where id = $1", id).StructScan(i); err != nil { + if err := utrx.QueryRowx("select * from frontends where id = $1", id).StructScan(i); err != nil { return nil, errors.Wrap(err, "error selecting frontend by id") } return i, nil } func (str *Store) FindFrontendWithToken(token string, tx *sqlx.Tx) (*Frontend, error) { + utrx := tx.Unsafe() i := &Frontend{} - if err := tx.QueryRowx("select frontends.* from frontends where token = $1 and not deleted", token).StructScan(i); err != nil { + if err := utrx.QueryRowx("select frontends.* from frontends where token = $1 and not deleted", token).StructScan(i); err != nil { return nil, errors.Wrap(err, "error selecting frontend by name") } return i, nil } func (str *Store) FindFrontendWithZId(zId string, tx *sqlx.Tx) (*Frontend, error) { + utrx := tx.Unsafe() i := &Frontend{} - if err := tx.QueryRowx("select frontends.* from frontends where z_id = $1 and not deleted", zId).StructScan(i); err != nil { + if err := utrx.QueryRowx("select frontends.* from frontends where z_id = $1 and not deleted", zId).StructScan(i); err != nil { return nil, errors.Wrap(err, "error selecting frontend by ziti id") } return i, nil } func (str *Store) FindFrontendPubliclyNamed(publicName string, tx *sqlx.Tx) (*Frontend, error) { + utrx := tx.Unsafe() i := &Frontend{} - if err := tx.QueryRowx("select frontends.* from frontends where public_name = $1 and not deleted", publicName).StructScan(i); err != nil { + if err := utrx.QueryRowx("select frontends.* from frontends where public_name = $1 and not deleted", publicName).StructScan(i); err != nil { return nil, errors.Wrap(err, "error selecting frontend by public_name") } return i, nil } func (str *Store) FindFrontendsForEnvironment(envId int, tx *sqlx.Tx) ([]*Frontend, error) { - rows, err := tx.Queryx("select frontends.* from frontends where environment_id = $1 and not deleted", envId) + utrx := tx.Unsafe() + rows, err := utrx.Queryx("select frontends.* from frontends where environment_id = $1 and not deleted", envId) if err != nil { return nil, errors.Wrap(err, "error selecting frontends by environment_id") } @@ -90,7 +95,8 @@ func (str *Store) FindFrontendsForEnvironment(envId int, tx *sqlx.Tx) ([]*Fronte } func (str *Store) FindPublicFrontends(tx *sqlx.Tx) ([]*Frontend, error) { - rows, err := tx.Queryx("select frontends.* from frontends where environment_id is null and reserved = true and not deleted") + utrx := tx.Unsafe() + rows, err := utrx.Queryx("select frontends.* from frontends where environment_id is null and reserved = true and not deleted") if err != nil { return nil, errors.Wrap(err, "error selecting public frontends") } @@ -106,7 +112,8 @@ func (str *Store) FindPublicFrontends(tx *sqlx.Tx) ([]*Frontend, error) { } func (str *Store) FindFrontendsForPrivateShare(shrId int, tx *sqlx.Tx) ([]*Frontend, error) { - rows, err := tx.Queryx("select frontends.* from frontends where private_share_id = $1 and not deleted", shrId) + utrx := tx.Unsafe() + rows, err := utrx.Queryx("select frontends.* from frontends where private_share_id = $1 and not deleted", shrId) if err != nil { return nil, errors.Wrap(err, "error selecting frontends by private_share_id") } diff --git a/controller/store/store.go b/controller/store/store.go index 6779344b..05683dd3 100644 --- a/controller/store/store.go +++ b/controller/store/store.go @@ -22,9 +22,10 @@ type Model struct { } type Config struct { - Path string `cf:"+secret"` - Type string - EnableLocking bool + Path string `cf:"+secret"` + Type string + EnableLocking bool + DisableAutoMigration bool } type Store struct { @@ -57,8 +58,10 @@ func Open(cfg *Config) (*Store, error) { dbx.MapperFunc(strcase.ToSnake) store := &Store{cfg: cfg, db: dbx} - if err := store.migrate(cfg); err != nil { - return nil, errors.Wrapf(err, "error migrating database '%v'", cfg.Path) + if !cfg.DisableAutoMigration { + if err := store.migrate(cfg); err != nil { + return nil, errors.Wrapf(err, "error migrating database '%v'", cfg.Path) + } } return store, nil } From e2448c6da8f1cab5ef8aa521e0e11ad89b1276a9 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 12 Feb 2025 11:11:43 -0500 Subject: [PATCH 2/2] changelog (#866) --- CHANGELOG.md | 2 ++ etc/ctrl.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e46918b4..e10727f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## v0.4.48 +FEATURE: The controller configuration now supports a `disable_auto_migration` boolean in the `store` stanza. When set to `true`, the controller will not attempt to auto-migrate (or otherwise validate the migration state) of the underlying database. Leaving `disable_auto_migration` out, or setting it to false will retain the default behavior of auto-migrating when starting the zrok controller. The `zrok admin migrate` command will still perform a migration regardless of how this setting is configured in the controller configuration (https://github.com/openziti/zrok/issues/866) + FIX: the Python SDK erroneously assumed the enabled zrok environment contained a config.json file, and was changed to only load it if the file was present (https://github.com/openziti/zrok/pull/853/). ## v0.4.47 diff --git a/etc/ctrl.yml b/etc/ctrl.yml index d9b0efd0..23f66b15 100644 --- a/etc/ctrl.yml +++ b/etc/ctrl.yml @@ -158,6 +158,7 @@ reset_password: #store: # path: "host=127.0.0.1 user=zrok password=zrok dbname=zrok" # type: "postgres" +# disable_auto_migration: true # store: path: zrok.db