Skip to content

Commit 13f2229

Browse files
author
Nikhil Pratap Singh
committed
Add support for mongo-driver v2
1 parent 2788339 commit 13f2229

File tree

8 files changed

+881
-32
lines changed

8 files changed

+881
-32
lines changed

build/migrate.linux-386

51.5 MB
Binary file not shown.

database/mongodb/mongodb_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ import (
77

88
"log"
99

10-
"github.com/golang-migrate/migrate/v4"
1110
"io"
1211
"os"
1312
"strconv"
1413
"testing"
1514
"time"
16-
)
1715

18-
import (
1916
"github.com/dhui/dktest"
17+
"github.com/golang-migrate/migrate/v4"
2018
"go.mongodb.org/mongo-driver/bson"
2119
"go.mongodb.org/mongo-driver/mongo"
2220
"go.mongodb.org/mongo-driver/mongo/options"
23-
)
2421

25-
import (
2622
dt "github.com/golang-migrate/migrate/v4/database/testing"
2723
"github.com/golang-migrate/migrate/v4/dktesting"
24+
2825
_ "github.com/golang-migrate/migrate/v4/source/file"
2926
)
3027

@@ -411,7 +408,7 @@ func waitForReplicaInit(client *mongo.Client) error {
411408
//during replica set initialization, the first node first becomes a secondary and then becomes the primary
412409
//should consider that initialization is completed only after the node has become the primary
413410
result := client.Database("admin").RunCommand(context.TODO(), bson.D{bson.E{Key: "isMaster", Value: 1}})
414-
r, err := result.DecodeBytes()
411+
r, err := result.Raw()
415412
if err != nil {
416413
return err
417414
}

database/mongodb/v2/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# MongoDB
2+
3+
* This package is for [mongo-go-driver/v2]. A backend for the older [monog-go-driver/v1]. is [also available](..).
4+
* Driver work with mongo through [db.runCommands](https://docs.mongodb.com/manual/reference/command/)
5+
* Migrations support json format. It contains array of commands for `db.runCommand`. Every command is executed in separate request to database
6+
* All keys have to be in quotes `"`
7+
* [Examples](./examples)
8+
9+
# Usage
10+
11+
`mongodb://user:password@host:port/dbname?query` (`mongodb+srv://` also works, but behaves a bit differently. See [docs](https://docs.mongodb.com/manual/reference/connection-string/#dns-seedlist-connection-format) for more information)
12+
13+
| URL Query | WithInstance Config | Description |
14+
|------------|---------------------|-------------|
15+
| `x-migrations-collection` | `MigrationsCollection` | Name of the migrations collection |
16+
| `x-transaction-mode` | `TransactionMode` | If set to `true` wrap commands in [transaction](https://docs.mongodb.com/manual/core/transactions). Available only for replica set. Driver is using [strconv.ParseBool](https://golang.org/pkg/strconv/#ParseBool) for parsing|
17+
| `x-advisory-locking` | `true` | Feature flag for advisory locking, if set to false, disable advisory locking |
18+
| `x-advisory-lock-collection` | `migrate_advisory_lock` | The name of the collection to use for advisory locking.|
19+
| `x-advisory-lock-timeout` | `15` | The max time in seconds that migrate will wait to acquire a lock before failing. |
20+
| `x-advisory-lock-timeout-interval` | `10` | The max time in seconds between attempts to acquire the advisory lock, the lock is attempted to be acquired using an exponential backoff algorithm. |
21+
| `dbname` | `DatabaseName` | The name of the database to connect to |
22+
| `user` | | The user to sign in as. Can be omitted |
23+
| `password` | | The user's password. Can be omitted |
24+
| `host` | | The host to connect to |
25+
| `port` | | The port to bind to |

0 commit comments

Comments
 (0)