diff --git a/README.md b/README.md index f698dd6..8c9c0d0 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,12 @@ Currently the command line utility supports only SqLite, the build in solution s ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("json") +MigrationProvider, err := migrator.NewMigrationProvider("json") if err != nil { panic("Error: " + err.Error()) } -err = migrator.Migrate(db, migrationProvider, migrationFilePath, count) +err = migrator.Migrate(db, MigrationProvider, migrationFilePath, count) if err != nil { panic("Error: " + err.Error()) } @@ -75,12 +75,12 @@ if err != nil { ## Example rollback: (where the db is your *sql.DB) ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("json", nil) +MigrationProvider, err := migrator.NewMigrationProvider("json", nil) if err != nil { panic("Error: " + err.Error()) } -err = migrator.Rollback(db, migrationProvider, migrationFilePath, count) +err = migrator.Rollback(db, MigrationProvider, migrationFilePath, count) if err != nil { panic("Error: " + err.Error()) } @@ -90,12 +90,12 @@ if err != nil { Refresh is when everithing rolled back and migrated from scratch ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("json", nil) +MigrationProvider, err := migrator.NewMigrationProvider("json", nil) if err != nil { panic("Error: " + err.Error()) } -err = migrator.Refresh(db, migrationProvider, migrationFilePath) +err = migrator.Refresh(db, MigrationProvider, migrationFilePath) if err != nil { panic("Error: " + err.Error()) } @@ -104,12 +104,12 @@ if err != nil { ## Migrate with database provider ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("db", db) +MigrationProvider, err := migrator.NewMigrationProvider("db", db) if err != nil { panic("Error: " + err.Error()) } -err = migrator.Migrate(db, migrationProvider, migrationFilePath, count) +err = migrator.Migrate(db, MigrationProvider, migrationFilePath, count) if err != nil { panic("Error: " + err.Error()) } @@ -118,12 +118,12 @@ if err != nil { ## Rollback with database provider ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("db", db) +MigrationProvider, err := migrator.NewMigrationProvider("db", db) if err != nil { panic("Error: " + err.Error()) } -err = migrator.Rollback(db, migrationProvider, migrationFilePath, count) +err = migrator.Rollback(db, MigrationProvider, migrationFilePath, count) if err != nil { panic("Error: " + err.Error()) } @@ -133,12 +133,12 @@ if err != nil { Refresh is when everithing rolled back and migrated from scratch ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("db", db) +MigrationProvider, err := migrator.NewMigrationProvider("db", db) if err != nil { panic("Error: " + err.Error()) } -err = migrator.Refresh(db, migrationProvider, migrationFilePath) +err = migrator.Refresh(db, MigrationProvider, migrationFilePath) if err != nil { panic("Error: " + err.Error()) } @@ -160,12 +160,12 @@ Fetching the migratio report to a readable string: ``` migrationFilePath := "./migration" -migrationProvider, err := migrator.NewMigrationProvider("db", db) +MigrationProvider, err := migrator.NewMigrationProvider("db", db) if err != nil { panic("Error: " + err.Error()) } -report, err := migrator.Report(db, migrationProvider, migrationFilePath) +report, err := migrator.Report(db, MigrationProvider, migrationFilePath) if err != nil { panic("Error: " + err.Error()) } diff --git a/cmd/cmd-run.go.bak b/cmd/cmd-run.go.bak index 9f012e6..6724a52 100644 --- a/cmd/cmd-run.go.bak +++ b/cmd/cmd-run.go.bak @@ -29,7 +29,7 @@ func main() { } defer db.Close() - migrationProvider, err := migrator.NewMigrationProvider(provider, db) + MigrationProvider, err := migrator.NewMigrationProvider(provider, db) if err != nil { panic(err.Error()) } @@ -40,13 +40,13 @@ func main() { switch function { case "migrate": - err = migrator.Migrate(db, migrationProvider, migrationFilePath, count) + err = migrator.Migrate(db, MigrationProvider, migrationFilePath, count) case "rollback": - err = migrator.Rollback(db, migrationProvider, migrationFilePath, count) + err = migrator.Rollback(db, MigrationProvider, migrationFilePath, count) case "refresh": - err = migrator.Refresh(db, migrationProvider, migrationFilePath) + err = migrator.Refresh(db, MigrationProvider, migrationFilePath) case "report": - report, err := migrator.Report(db, migrationProvider, migrationFilePath) + report, err := migrator.Report(db, MigrationProvider, migrationFilePath) if err != nil { panic("Error: " + err.Error()) } diff --git a/migration.go b/migration.go index 162bed6..8c5faef 100644 --- a/migration.go +++ b/migration.go @@ -10,7 +10,7 @@ import ( type migration struct { db *sql.DB - migrationProvider migrationProvider + MigrationProvider MigrationProvider migrationFilePath string } @@ -42,7 +42,7 @@ func (m *migration) orderedMigrationFiles() ([]string, error) { } func (m *migration) executeSQLFile(fileName string) (bool, error) { - exists, err := m.migrationProvider.migrationExistsForFile(fileName) + exists, err := m.MigrationProvider.migrationExistsForFile(fileName) if err != nil { return false, err } @@ -59,13 +59,13 @@ func (m *migration) executeSQLFile(fileName string) (bool, error) { err = m.executeSQL(string(content)) if err == nil { - err = m.migrationProvider.addToMigration(fileName) + err = m.MigrationProvider.addToMigration(fileName) if err != nil { return false, err } } - _ = m.migrationProvider.AddToMigrationReport(fileName, err) + _ = m.MigrationProvider.addToMigrationReport(fileName, err) return true, err } @@ -74,7 +74,7 @@ func (m *migration) executeRollbackSQLFile(fileName string) error { rollbackFileName, err := m.resolveRollbackFile(fileName) if err != nil { fmt.Printf("Skip rollback for %s as rollback file does not exists\n", fileName) - err := m.migrationProvider.removeFromMigration(fileName) + err := m.MigrationProvider.removeFromMigration(fileName) if err != nil { return err } @@ -90,13 +90,13 @@ func (m *migration) executeRollbackSQLFile(fileName string) error { err = m.executeSQL(string(content)) if err == nil { - err = m.migrationProvider.removeFromMigration(fileName) + err = m.MigrationProvider.removeFromMigration(fileName) if err != nil { return err } } - err = m.migrationProvider.AddToMigrationReport(rollbackFileName, err) + err = m.MigrationProvider.addToMigrationReport(rollbackFileName, err) return err } diff --git a/migration_db_provider.go b/migration_db_provider.go index f42caa7..f6beab9 100644 --- a/migration_db_provider.go +++ b/migration_db_provider.go @@ -242,7 +242,7 @@ func (m *dbMigration) SetJSONFilePath(_ string) { // dummy, not used in db version, need due to interface } -func (m *dbMigration) AddToMigrationReport(fileName string, errorToLog error) error { +func (m *dbMigration) addToMigrationReport(fileName string, errorToLog error) error { sql := fmt.Sprintf(`INSERT INTO migration_reports (file_name, created_at, result_status, message) VALUES (%s, %s, %s, %s)`, diff --git a/migration_json_provider.go b/migration_json_provider.go index c031f38..df50b44 100644 --- a/migration_json_provider.go +++ b/migration_json_provider.go @@ -127,7 +127,7 @@ func (m *jsonMigration) SetJSONFilePath(filePath string) { m.jsonReporFileName = filePath + "/migration_reports.json" } -func (m *jsonMigration) AddToMigrationReport(fileName string, errorToLog error) error { +func (m *jsonMigration) addToMigrationReport(fileName string, errorToLog error) error { storeFileName := m.getJSONReportFileName() message := "ok" status := "success" diff --git a/migration_provider.go b/migration_provider.go index 60552ca..fb94363 100644 --- a/migration_provider.go +++ b/migration_provider.go @@ -5,7 +5,8 @@ import ( "fmt" ) -type migrationProvider interface { +// MigrationProvider is the base migrator interface +type MigrationProvider interface { migrations(bool) ([]string, error) addToMigration(string) error removeFromMigration(string) error @@ -13,14 +14,14 @@ type migrationProvider interface { resetDate() getJSONFileName() string SetJSONFilePath(string) - AddToMigrationReport(string, error) error + addToMigrationReport(string, error) error Report() (string, error) } // NewMigrationProvider returns a migration provider, which follows the provider type // The provider type can be json or db, error returned if the type incorrectly provided // db should be your database *sql.DB, which can be MySQL, Postgres, Sqlite or Firebird -func NewMigrationProvider(providerType string, db *sql.DB) (migrationProvider, error) { +func NewMigrationProvider(providerType string, db *sql.DB) (MigrationProvider, error) { switch providerType { case "json": return newJSONMigration() diff --git a/migrator.go b/migrator.go index c8580fb..749db12 100644 --- a/migrator.go +++ b/migrator.go @@ -11,39 +11,39 @@ import ( // Rollback rolls back last migrated items or all if count is 0 func Rollback( db *sql.DB, - migrationProvider migrationProvider, + MigrationProvider MigrationProvider, migrationFilePath string, count int, ) error { - return rollback(db, migrationProvider, migrationFilePath, count, false) + return rollback(db, MigrationProvider, migrationFilePath, count, false) } // Refresh runs a full rollback and migrate again func Refresh( db *sql.DB, - migrationProvider migrationProvider, + MigrationProvider MigrationProvider, migrationFilePath string, ) error { - err := rollback(db, migrationProvider, migrationFilePath, 0, true) + err := rollback(db, MigrationProvider, migrationFilePath, 0, true) if err != nil { return err } - return Migrate(db, migrationProvider, migrationFilePath, 0) + return Migrate(db, MigrationProvider, migrationFilePath, 0) } // Migrate execute migrations func Migrate( db *sql.DB, - migrationProvider migrationProvider, + MigrationProvider MigrationProvider, migrationFilePath string, count int, ) error { m := newMigrator(db) m.migrationFilePath = migrationFilePath - m.migrationProvider = migrationProvider - m.migrationProvider.SetJSONFilePath(migrationFilePath) - m.migrationProvider.resetDate() + m.MigrationProvider = MigrationProvider + m.MigrationProvider.SetJSONFilePath(migrationFilePath) + m.MigrationProvider.resetDate() fileNames, err := m.orderedMigrationFiles() if err != nil { return err @@ -74,15 +74,15 @@ func Migrate( // Report return a report of the alredy executed migrations func Report( db *sql.DB, - migrationProvider migrationProvider, + MigrationProvider MigrationProvider, migrationFilePath string, ) (string, error) { m := newMigrator(db) m.migrationFilePath = migrationFilePath - m.migrationProvider = migrationProvider - m.migrationProvider.SetJSONFilePath(migrationFilePath) - return m.migrationProvider.Report() + m.MigrationProvider = MigrationProvider + m.MigrationProvider.SetJSONFilePath(migrationFilePath) + return m.MigrationProvider.Report() } // AddNewMigrationFiles adds a new blank migration file and a rollback file @@ -102,7 +102,7 @@ func AddNewMigrationFiles(migrationFilePath, customText string) error { func rollback( db *sql.DB, - migrationProvider migrationProvider, + MigrationProvider MigrationProvider, migrationFilePath string, count int, isCompleteRollback bool, @@ -110,9 +110,9 @@ func rollback( var err error m := newMigrator(db) m.migrationFilePath = migrationFilePath - m.migrationProvider = migrationProvider - m.migrationProvider.SetJSONFilePath(migrationFilePath) - migrations, err := m.migrationProvider.migrations(!isCompleteRollback) + m.MigrationProvider = MigrationProvider + m.MigrationProvider.SetJSONFilePath(migrationFilePath) + migrations, err := m.MigrationProvider.migrations(!isCompleteRollback) if err != nil { return err } diff --git a/test/migrator_migrate_db_test.go b/test/migrator_migrate_db_test.go index c95837f..a99c419 100644 --- a/test/migrator_migrate_db_test.go +++ b/test/migrator_migrate_db_test.go @@ -30,10 +30,10 @@ func (suite *DbTestSuite) TearDownTest() { } func (t *DbTestSuite) TestDBMigratorMigrateAllTables() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -50,10 +50,10 @@ func (t *DbTestSuite) TestDBMigratorMigrateAllTables() { func (t *DbTestSuite) TestDBMigratorMigrateSpeciedAmountOfTables() { migrateCount := 2 - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -61,7 +61,7 @@ func (t *DbTestSuite) TestDBMigratorMigrateSpeciedAmountOfTables() { t.Equal(4, tableCount) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -69,7 +69,7 @@ func (t *DbTestSuite) TestDBMigratorMigrateSpeciedAmountOfTables() { t.Equal(6, tableCount) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -79,10 +79,10 @@ func (t *DbTestSuite) TestDBMigratorMigrateSpeciedAmountOfTables() { } func (t *DbTestSuite) TestDBMigratorRollbackAllTables() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -90,7 +90,7 @@ func (t *DbTestSuite) TestDBMigratorRollbackAllTables() { t.Equal(7, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -100,10 +100,10 @@ func (t *DbTestSuite) TestDBMigratorRollbackAllTables() { } func (t *DbTestSuite) TestDBMigratorRollbackSpecificAmountOfTables() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -111,7 +111,7 @@ func (t *DbTestSuite) TestDBMigratorRollbackSpecificAmountOfTables() { t.Equal(7, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -119,7 +119,7 @@ func (t *DbTestSuite) TestDBMigratorRollbackSpecificAmountOfTables() { t.Equal(5, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -129,16 +129,16 @@ func (t *DbTestSuite) TestDBMigratorRollbackSpecificAmountOfTables() { } func (t *DbTestSuite) TestDBMigratorRollsBackTablesInProperBatches() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 1) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 1) t.Nil(err) time.Sleep(time.Second) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) time.Sleep(time.Second) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -146,7 +146,7 @@ func (t *DbTestSuite) TestDBMigratorRollsBackTablesInProperBatches() { t.Equal(7, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -154,7 +154,7 @@ func (t *DbTestSuite) TestDBMigratorRollsBackTablesInProperBatches() { t.Equal(5, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -162,7 +162,7 @@ func (t *DbTestSuite) TestDBMigratorRollsBackTablesInProperBatches() { t.Equal(3, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -172,10 +172,10 @@ func (t *DbTestSuite) TestDBMigratorRollsBackTablesInProperBatches() { } func (t *DbTestSuite) TestDBRefresh() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 3) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 3) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -183,7 +183,7 @@ func (t *DbTestSuite) TestDBRefresh() { t.Equal(5, tableCount) - err = migrator.Refresh(t.db, migrationProvider, testFixtureFolder) + err = migrator.Refresh(t.db, MigrationProvider, testFixtureFolder) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) diff --git a/test/migrator_migrate_json_test.go b/test/migrator_migrate_json_test.go index cad7ea3..2ff9593 100644 --- a/test/migrator_migrate_json_test.go +++ b/test/migrator_migrate_json_test.go @@ -29,10 +29,10 @@ func (suite *JsonTestSuite) TearDownTest() { } func (t *JsonTestSuite) TestJsonMigratorMigrateAllTables() { - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -44,10 +44,10 @@ func (t *JsonTestSuite) TestJsonMigratorMigrateAllTables() { func (t *JsonTestSuite) TestJsonMigratorMigrateSpeciedAmountOfTables() { migrateCount := 2 - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -55,7 +55,7 @@ func (t *JsonTestSuite) TestJsonMigratorMigrateSpeciedAmountOfTables() { t.Equal(2, tableCount) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -63,7 +63,7 @@ func (t *JsonTestSuite) TestJsonMigratorMigrateSpeciedAmountOfTables() { t.Equal(4, tableCount) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, migrateCount) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, migrateCount) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -73,10 +73,10 @@ func (t *JsonTestSuite) TestJsonMigratorMigrateSpeciedAmountOfTables() { } func (t *JsonTestSuite) TestJsonMigratorRollbackAllTables() { - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -84,7 +84,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollbackAllTables() { t.Equal(5, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -94,10 +94,10 @@ func (t *JsonTestSuite) TestJsonMigratorRollbackAllTables() { } func (t *JsonTestSuite) TestJsonMigratorRollbackSpecificAmountOfTables() { - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -105,7 +105,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollbackSpecificAmountOfTables() { t.Equal(5, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -113,7 +113,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollbackSpecificAmountOfTables() { t.Equal(3, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -123,16 +123,16 @@ func (t *JsonTestSuite) TestJsonMigratorRollbackSpecificAmountOfTables() { } func (t *JsonTestSuite) TestJsonMigratorRollsBackTablesInProperBatches() { - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 1) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 1) t.Nil(err) time.Sleep(time.Second) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) time.Sleep(time.Second) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 2) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 2) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -140,7 +140,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollsBackTablesInProperBatches() { t.Equal(5, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -148,7 +148,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollsBackTablesInProperBatches() { t.Equal(3, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -156,7 +156,7 @@ func (t *JsonTestSuite) TestJsonMigratorRollsBackTablesInProperBatches() { t.Equal(1, tableCount) - err = migrator.Rollback(t.db, migrationProvider, testFixtureFolder, 0) + err = migrator.Rollback(t.db, MigrationProvider, testFixtureFolder, 0) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) @@ -166,10 +166,10 @@ func (t *JsonTestSuite) TestJsonMigratorRollsBackTablesInProperBatches() { } func (t *JsonTestSuite) TestJsonRefresh() { - migrationProvider, err := migrator.NewMigrationProvider("json", nil) + MigrationProvider, err := migrator.NewMigrationProvider("json", nil) t.Nil(err) - err = migrator.Migrate(t.db, migrationProvider, testFixtureFolder, 3) + err = migrator.Migrate(t.db, MigrationProvider, testFixtureFolder, 3) t.Nil(err) tableCount, err := tableCountInDatabase(t.db) @@ -177,7 +177,7 @@ func (t *JsonTestSuite) TestJsonRefresh() { t.Equal(3, tableCount) - err = migrator.Refresh(t.db, migrationProvider, testFixtureFolder) + err = migrator.Refresh(t.db, MigrationProvider, testFixtureFolder) t.Nil(err) tableCount, err = tableCountInDatabase(t.db) diff --git a/test/migrator_report_db_test.go b/test/migrator_report_db_test.go index e7bdea7..b74f543 100644 --- a/test/migrator_report_db_test.go +++ b/test/migrator_report_db_test.go @@ -26,7 +26,7 @@ func (suite *ReportDbTestSuite) TearDownTest() { } func (t *ReportDbTestSuite) TestDBMigratorMigrateAllTables() { - migrationProvider, err := migrator.NewMigrationProvider("db", t.db) + MigrationProvider, err := migrator.NewMigrationProvider("db", t.db) t.Nil(err) err = haveReportrecord(t.db, "FN1", "2006-01-01 00:00:00", "success", "ok") @@ -35,7 +35,7 @@ func (t *ReportDbTestSuite) TestDBMigratorMigrateAllTables() { err = haveReportrecord(t.db, "FN2", "2006-01-02 00:00:00", "error", "table not exists") t.Nil(err) - report, err := migrationProvider.Report() + report, err := MigrationProvider.Report() t.Nil(err) expected := "Created at: 2006-01-01T00:00:00Z, File Name: FN1, Status: success, Message: ok\nCreated at: 2006-01-02T00:00:00Z, File Name: FN2, Status: error, Message: table not exists\n" diff --git a/test/migrator_report_json_test.go b/test/migrator_report_json_test.go index 480bb04..fd38980 100644 --- a/test/migrator_report_json_test.go +++ b/test/migrator_report_json_test.go @@ -32,11 +32,11 @@ func (t *ReportTestSuite) TestDBMigratorMigrateAllTables() { err := copyFile(reportSourceFixture, reportDestinationFixture) t.Nil(err) - migrationProvider, err := migrator.NewMigrationProvider("json", t.db) - migrationProvider.SetJSONFilePath(testFixtureFolder) + MigrationProvider, err := migrator.NewMigrationProvider("json", t.db) + MigrationProvider.SetJSONFilePath(testFixtureFolder) t.Nil(err) - report, err := migrationProvider.Report() + report, err := MigrationProvider.Report() t.Nil(err) expected := "Created at: 2024-05-27 14:12:31, File Name: 2023-07-27_17_57_47-migrate-fixture.sql, Status: success, Message: ok\nCreated at: 2024-05-27 14:12:31, File Name: 2023-07-27_17_57_50-migrate-fixture.sql, Status: success, Message: ok\n"