Conversation
akshah123
pushed a commit
to akshah123/goose
that referenced
this pull request
Dec 14, 2025
This adds a complete locking mechanism for SQL Server, similar to the existing PostgreSQL implementation from PR pressly#993. Features: - Table-based locking using MERGE for atomic upserts - Session-based locking using sp_getapplock/sp_releaseapplock - Automatic lease renewal via heartbeat mechanism - Stale lock cleanup for expired leases Implementation: - lock/internal/store/sqlserver.go: LockStore implementation - lock/sqlserver.go: Public API (NewSqlserverTableLocker, NewSqlserverSessionLocker) - internal/testing/testdb/sqlserver.go: Docker test helper - SQL Server specific test migrations - Comprehensive integration tests for both locking modes The table-based locker uses SQL Server's MERGE statement with HOLDLOCK for atomic lock acquisition and SYSUTCDATETIME() for server-side time. The session-based locker uses SQL Server's built-in application lock stored procedures which provide session-level advisory locking.
6 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #972 and should help with improved goose support for cockroachdb/cockroach#13546 and PgBouncer when used with transaction pooling.
This PR adds a few things.
WithLockerwhich uses the newlock.Lockerinterface:Note, although we added Postgres support, this could easily be extended to other databases either via a custom
Lockerimplementation or a solid PR within Goose for one of the natively supported databases.NewPostgresTableLockerimplementation which uses a new tablegoose_lock(configurable) to provide connection-independent locking with automatic lease expirationUsage:
The defaults are documented, but I'll add them here for brevity.
In other words, when multiple instances start simultaneously, one acquires the lock and runs migrations (refreshing every 5 seconds) while others retry every 5 seconds for up to 5 minutes, with automatic failover after 30 seconds if the heartbeat stops.