Skip to content

Commit fa12828

Browse files
committed
rm force lock
1 parent 677160f commit fa12828

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

database/ydb/README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
| `port` | The port to bind to. |
1111
| `database` | The name of the database to connect to. |
1212

13-
| URL Query Params | Description |
14-
|:----------------------------:|:--------------------------------------------------------------------------------------------------------------------------:|
15-
| `x-auth-token` | Authentication token. |
16-
| `x-migrations-table` | Name of the migrations table (default `schema_migrations`). |
17-
| `x-lock-table` | Name of the table which maintains the migration lock (default `schema_lock`). |
18-
| `x-force-lock` | Enables force lock acquisition to fix faulty migrations which may not have released the schema lock (disabled by default). |
19-
| `x-use-grpcs` | Enables gRPCS protocol for YDB connections (default grpc). |
20-
| `x-tls-ca` | The location of the CA (certificate authority) file. |
21-
| `x-tls-insecure-skip-verify` | Controls whether a client verifies the server's certificate chain and host name. |
22-
| `x-tls-min-version` | Controls the minimum TLS version that is acceptable, use 1.0, 1.1, 1.2 or 1.3 (default 1.2). |
13+
| URL Query Params | Description |
14+
|:----------------------------:|:--------------------------------------------------------------------------------------------:|
15+
| `x-auth-token` | Authentication token. |
16+
| `x-migrations-table` | Name of the migrations table (default `schema_migrations`). |
17+
| `x-lock-table` | Name of the table which maintains the migration lock (default `schema_lock`). |
18+
| `x-use-grpcs` | Enables gRPCS protocol for YDB connections (default grpc). |
19+
| `x-tls-ca` | The location of the CA (certificate authority) file. |
20+
| `x-tls-insecure-skip-verify` | Controls whether a client verifies the server's certificate chain and host name. |
21+
| `x-tls-min-version` | Controls the minimum TLS version that is acceptable, use 1.0, 1.1, 1.2 or 1.3 (default 1.2). |
2322

2423
### Secure connection
2524

@@ -39,4 +38,11 @@ Through the url query, you can change the default behavior:
3938
`ydb://user:password@host:port/database`
4039
- To connect to YDB using [token](https://ydb.tech/docs/en/recipes/ydb-sdk/auth-access-token) you need to specify token
4140
as query parameter:
42-
`ydb://host:port/database?x-auth-token=<YDB_TOKEN>`
41+
`ydb://host:port/database?x-auth-token=<YDB_TOKEN>`
42+
43+
### Locks
44+
45+
If golang-migrate fails to acquire the lock and no migrations are currently running.
46+
This may indicate that one of the migrations did not complete successfully.
47+
In this case, you need to analyze the previous migrations, rollback if necessary, and manually remove the lock from the
48+
`x-lock-table`.

database/ydb/ydb.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const (
2929
queryParamAuthToken = "x-auth-token"
3030
queryParamMigrationsTable = "x-migrations-table"
3131
queryParamLockTable = "x-lock-table"
32-
queryParamForceLock = "x-force-lock"
3332
queryParamUseGRPCS = "x-use-grpcs"
3433
queryParamTLSCertificateAuthorities = "x-tls-ca"
3534
queryParamTLSInsecureSkipVerify = "x-tls-insecure-skip-verify"
@@ -46,7 +45,6 @@ type Config struct {
4645
MigrationsTable string
4746
LockTable string
4847
DatabaseName string
49-
ForceLock bool
5048
}
5149

5250
type YDB struct {
@@ -144,7 +142,6 @@ func (y *YDB) Open(dsn string) (database.Driver, error) {
144142
MigrationsTable: pquery.Get(queryParamMigrationsTable),
145143
LockTable: pquery.Get(queryParamLockTable),
146144
DatabaseName: purl.Path,
147-
ForceLock: pquery.Has(queryParamForceLock),
148145
})
149146
if err != nil {
150147
return nil, err
@@ -328,12 +325,9 @@ func (y *YDB) Lock() error {
328325

329326
// If row exists at all, lock is present
330327
locked := rows.Next()
331-
if locked && !y.config.ForceLock {
328+
if locked {
332329
return database.ErrLocked
333330
}
334-
if locked && y.config.ForceLock {
335-
return nil
336-
}
337331

338332
setLockQuery := fmt.Sprintf("INSERT INTO %s (lock_id) VALUES ('%s')", y.config.LockTable, aid)
339333
if _, err = tx.Exec(setLockQuery); err != nil {

0 commit comments

Comments
 (0)