-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the postgres migrations in two ways:
1) Make each non-transactional migration step contain only a single migration operation. This ensures that if the operation fails, we don't end up "halfway" into a migration step. In the future, we'll enforce this via testing. 2) Change how concurrent indexes are created. See: https://www.shayon.dev/post/2024/225/stop-relying-on-if-not-exists-for-concurrent-index-creation-in-postgresql/ for why this is important
- Loading branch information
1 parent
31b08ba
commit fa1c4fe
Showing
4 changed files
with
61 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
internal/datastore/postgres/migrations/zz_migration.0022_add_expiration_index.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jackc/pgx/v5" | ||
) | ||
|
||
const dropExpiredRelationshipsIndex = ` | ||
DROP INDEX CONCURRENTLY IF EXISTS ix_relation_tuple_expired; | ||
` | ||
|
||
// Used for cleaning up expired relationships. | ||
const addExpiredRelationshipsIndex = ` | ||
CREATE INDEX CONCURRENTLY | ||
ix_relation_tuple_expired | ||
ON relation_tuple (expiration) | ||
WHERE expiration IS NOT NULL; | ||
` | ||
|
||
func init() { | ||
if err := DatabaseMigrations.Register("add-expiration-cleanup-index", "add-expiration-support", | ||
func(ctx context.Context, conn *pgx.Conn) error { | ||
if _, err := conn.Exec(ctx, dropExpiredRelationshipsIndex); err != nil { | ||
return fmt.Errorf("failed to drop watch API index to relation tuple table: %w", err) | ||
} | ||
|
||
if _, err := conn.Exec(ctx, addExpiredRelationshipsIndex); err != nil { | ||
return fmt.Errorf("failed to add expiration column to relation tuple table: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
noTxMigration); err != nil { | ||
panic("failed to register migration: " + err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters