MCPcopy Index your code
hub / github.com/coder/coder / EnsureClean

Function EnsureClean

coderd/database/migrations/migrate.go:174–197  ·  view source on GitHub ↗

EnsureClean checks whether all migrations for the current version have been applied, without making any changes to the database. If not, returns a non-nil error.

(db *sql.DB)

Source from the content-addressed store, hash-verified

172// applied, without making any changes to the database. If not, returns a
173// non-nil error.
174func EnsureClean(db *sql.DB) error {
175 sourceDriver, m, err := setup(db, migrations)
176 if err != nil {
177 return xerrors.Errorf("migrate setup: %w", err)
178 }
179
180 version, dirty, err := m.Version()
181 if err != nil {
182 return xerrors.Errorf("get migration version: %w", err)
183 }
184
185 if dirty {
186 return xerrors.Errorf("database has not been cleanly migrated")
187 }
188
189 // Verify that the database's migration version is "current" by checking
190 // that a migration with that version exists, but there is no next version.
191 err = CheckLatestVersion(sourceDriver, version)
192 if err != nil {
193 return xerrors.Errorf("database needs migration: %w", err)
194 }
195
196 return nil
197}
198
199// Returns nil if currentVersion corresponds to the latest available migration,
200// otherwise an error explaining why not.

Callers 1

ConnectToPostgresFunction · 0.92

Calls 4

CheckLatestVersionFunction · 0.85
VersionMethod · 0.80
setupFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected