@@ -90,6 +90,7 @@ func (p prefixedNames) getNames() []string {
90
90
func Migrate (db * pgxpool.Pool , versionInfo VersionInfo ) (err error ) {
91
91
migrateMutex .Lock ()
92
92
defer migrateMutex .Unlock ()
93
+ ExtensionIsInstalled = false
93
94
94
95
// Getting an early connection to install the extra extension.
95
96
// TODO: Investigate why this is required. Installing the extension on the
@@ -115,6 +116,10 @@ func Migrate(db *pgxpool.Pool, versionInfo VersionInfo) (err error) {
115
116
116
117
// If already at correct version, nothing to migrate.
117
118
if dbVersion .Compare (appVersion ) == 0 {
119
+ installExtension (conn )
120
+
121
+ metadataUpdate (db , ExtensionIsInstalled , "version" , versionInfo .Version )
122
+ metadataUpdate (db , ExtensionIsInstalled , "commit_hash" , versionInfo .CommitHash )
118
123
return nil
119
124
}
120
125
@@ -155,13 +160,7 @@ func Migrate(db *pgxpool.Pool, versionInfo VersionInfo) (err error) {
155
160
return fmt .Errorf ("unable to commit migration transaction: %w" , err )
156
161
}
157
162
158
- _ , extErr := conn .Exec (context .Background (), fmt .Sprintf (extensionInstall , extSchema ))
159
- if extErr != nil {
160
- log .Warn ("msg" , "timescale_prometheus_extra extension not installed" , "cause" , extErr )
161
- ExtensionIsInstalled = false
162
- } else {
163
- ExtensionIsInstalled = true
164
- }
163
+ installExtension (conn )
165
164
166
165
metadataUpdate (db , ExtensionIsInstalled , "version" , versionInfo .Version )
167
166
metadataUpdate (db , ExtensionIsInstalled , "commit_hash" , versionInfo .CommitHash )
@@ -361,6 +360,16 @@ func upgradeVersion(tx pgx.Tx, from, to semver.Version) error {
361
360
return nil
362
361
}
363
362
363
+ func installExtension (conn * pgxpool.Conn ) {
364
+ _ , extErr := conn .Exec (context .Background (), fmt .Sprintf (extensionInstall , extSchema ))
365
+ if extErr != nil {
366
+ log .Warn ("msg" , "timescale_prometheus_extra extension not installed" , "cause" , extErr )
367
+ ExtensionIsInstalled = false
368
+ } else {
369
+ ExtensionIsInstalled = true
370
+ }
371
+ }
372
+
364
373
func setDBVersion (tx pgx.Tx , version * semver.Version ) error {
365
374
if _ , err := tx .Exec (context .Background (), truncateMigrationsTable ); err != nil {
366
375
return fmt .Errorf ("unable to truncate migrations table: %w" , err )
0 commit comments