[MM-41576] Add schema version to the client configuration (#19757)
* revamp db version and add applied migrations endpoint * replace old schema version with new * add db version subcommand * add to local api * reflect review comments * log errors * remove setting the version from model.CurrentVersion * fix a test * use different field for schema version * add build hash and current version to the support packet * add tests * update test to use new assets
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
47c44a9b7d
Коммит
b03d87af40
@@ -353,10 +353,10 @@ func (ss *SqlStore) DriverName() string {
|
||||
return *ss.settings.DriverName
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetCurrentSchemaVersion() string {
|
||||
func (ss *SqlStore) getCurrentSchemaVersion() (string, error) {
|
||||
var version string
|
||||
_ = ss.GetMasterX().Get(&version, "SELECT Value FROM Systems WHERE Name='Version'")
|
||||
return version
|
||||
err := ss.GetMasterX().Get(&version, "SELECT Value FROM Systems WHERE Name='Version'")
|
||||
return version, err
|
||||
}
|
||||
|
||||
// GetDbVersion returns the version of the database being used.
|
||||
@@ -949,6 +949,7 @@ func (ss *SqlStore) DropAllTables() {
|
||||
FROM pg_class
|
||||
WHERE relkind = 'r' -- only tables
|
||||
AND relnamespace = 'public'::regnamespace
|
||||
AND NOT relname = 'db_migrations'
|
||||
);
|
||||
END
|
||||
$func$;`)
|
||||
@@ -956,7 +957,9 @@ func (ss *SqlStore) DropAllTables() {
|
||||
tables := []string{}
|
||||
ss.masterX.Select(&tables, `show tables`)
|
||||
for _, t := range tables {
|
||||
ss.masterX.Exec(`TRUNCATE TABLE ` + t)
|
||||
if t != "db_migrations" {
|
||||
ss.masterX.Exec(`TRUNCATE TABLE ` + t)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1204,3 +1207,20 @@ func (ss *SqlStore) toReserveCase(str string) string {
|
||||
|
||||
return fmt.Sprintf("`%s`", strings.Title(str))
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetDBSchemaVersion() (int, error) {
|
||||
var version int
|
||||
if err := ss.GetMasterX().Get(&version, "SELECT Version FROM db_migrations ORDER BY Version DESC LIMIT 1"); err != nil {
|
||||
return 0, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetAppliedMigrations() ([]model.AppliedMigration, error) {
|
||||
migrations := []model.AppliedMigration{}
|
||||
if err := ss.GetMasterX().Select(&migrations, "SELECT Version, Name FROM db_migrations ORDER BY Version DESC"); err != nil {
|
||||
return nil, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
|
||||
return migrations, nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user