|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - log "github.com/Sirupsen/logrus" |
5 | 4 | _ "github.com/go-sql-driver/mysql" |
6 | | - "github.com/jmoiron/sqlx" |
7 | 5 | "github.com/qa-dev/jsonwire-grid/config" |
8 | | - "github.com/qa-dev/jsonwire-grid/pool" |
9 | 6 |
|
10 | 7 | "errors" |
11 | | - mysqlMigrations "github.com/qa-dev/jsonwire-grid/storage/migrations/mysql" |
| 8 | + "github.com/qa-dev/jsonwire-grid/storage" |
12 | 9 | "github.com/qa-dev/jsonwire-grid/storage/mysql" |
13 | | - "github.com/rubenv/sql-migrate" |
14 | 10 | ) |
15 | 11 |
|
16 | | -func invokeStorage(config config.Config) (storage pool.StorageInterface, err error) { |
| 12 | +func invokeStorageFactory(config config.Config) (factory storage.StorageFactoryInterface, err error) { |
17 | 13 | switch config.DB.Implementation { |
18 | 14 | case "mysql": |
19 | | - var db *sqlx.DB |
20 | | - db, err = sqlx.Open("mysql", config.DB.Connection) |
21 | | - if err != nil { |
22 | | - err = errors.New("Database connection error: " + err.Error()) |
23 | | - return |
24 | | - } |
25 | | - |
26 | | - storage = mysql.NewMysqlStorage(db) |
27 | | - |
28 | | - migrations := &migrate.AssetMigrationSource{ |
29 | | - Asset: mysqlMigrations.Asset, |
30 | | - AssetDir: mysqlMigrations.AssetDir, |
31 | | - Dir: "storage/migrations/mysql", |
32 | | - } |
33 | | - var n int |
34 | | - n, err = migrate.Exec(db.DB, "mysql", migrations, migrate.Up) |
35 | | - if err != nil { |
36 | | - err = errors.New("Migrations failed, " + err.Error()) |
37 | | - return |
38 | | - } |
39 | | - log.Infof("Applied %d migrations!\n", n) |
| 15 | + factory = new(mysql.Factory) |
40 | 16 | default: |
41 | | - err = errors.New("Invalid config, unknown param [DB.Implementation=" + config.DB.Implementation + "]") |
| 17 | + err = errors.New("Invalid config, unknown param [db.implementation=" + config.DB.Implementation + "]") |
42 | 18 | } |
43 | 19 | return |
44 | 20 | } |
0 commit comments