/
migrate.go
60 lines (47 loc) · 1.33 KB
/
migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"github.com/naufalfmm/mongodb-migration/client"
"github.com/naufalfmm/mongodb-migration/constants"
"github.com/naufalfmm/mongodb-migration/config"
"github.com/naufalfmm/mongodb-migration/constants/direction"
"github.com/naufalfmm/mongodb-migration/constants/steps"
"github.com/naufalfmm/mongodb-migration/driver"
"github.com/naufalfmm/mongodb-migration/history"
"github.com/naufalfmm/mongodb-migration/migration"
)
func main() {
var (
DBName = "db_migration_trial"
DBUser = "user"
DBPassword = "123456789"
DBHost = "localhost"
DBPort = "27017"
cfg = config.Config{
Name: DBName,
User: DBUser,
Password: DBPassword,
Host: DBHost,
Port: DBPort,
}
client = client.MongoClient{}
migr = migration.MongoMigration{}
mongoDriver = driver.MongoDriver{}
)
ctx := context.TODO()
cfg.SetURI()
mongoDriver.Client = &client
mongoDriver.SetClientWithContext(ctx, &cfg)
historyRecord := history.MigrationRecord{
DB: mongoDriver.GetDB(),
CollectionName: constants.DEFAULT_MIGRATION_HISTORY_COLLECTION,
}
err := migr.StartMigrationWithDriver(ctx, "./example/migrate/migrations/", &mongoDriver, &historyRecord)
if err != nil {
panic(err)
}
err = migr.Run(ctx, direction.UP, steps.ALL)
if err != nil {
panic(err)
}
}