diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d4b4f5..d5f0a4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: services: postgres: - image: "postgres:11" + image: "postgres:12" env: POSTGRES_PASSWORD: morph POSTGRES_DB: morph_test @@ -31,7 +31,7 @@ jobs: - 6432:5432 mysql: - image: "mysql:5.7" + image: "mysql:8" env: MYSQL_DATABASE: morph_test MYSQL_USER: morph diff --git a/cmd/morph/morph.go b/cmd/morph/morph.go index 00d9919..f6eedd9 100644 --- a/cmd/morph/morph.go +++ b/cmd/morph/morph.go @@ -20,5 +20,6 @@ func main() { morph.ErrorLogger.Fprintf(os.Stderr, "An Error Occurred:\n") } _, _ = morph.ErrorLoggerLight.Fprintf(os.Stderr, "--> %v\n", err) + os.Exit(1) } } diff --git a/docker-compose.yml b/docker-compose.yml index 948a02c..d4a1d20 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.1' services: postgres: - image: postgres + image: postgres:12 restart: always ports: - "6432:5432" @@ -10,7 +10,7 @@ services: POSTGRES_DB: morph_test POSTGRES_USER: morph mysql: - image: "mysql:5.7" + image: "mysql:8" restart: always ports: - "3307:3306" diff --git a/drivers/driver.go b/drivers/driver.go index a39cdde..2a2ab99 100644 --- a/drivers/driver.go +++ b/drivers/driver.go @@ -5,19 +5,27 @@ import ( ) type Config struct { + // MigrationsTableName is the name of the table that will store the migrations. MigrationsTable string // StatementTimeoutInSecs is used to set a timeout for each migration file. // Set below zero to disable timeout. Zero value will result in default value, which is 60 seconds. StatementTimeoutInSecs int - MigrationMaxSize int + // MigrationMaxSize is the maximum size of a migration file in bytes. + MigrationMaxSize int } +// Driver is the interface that should be implemented by all drivers. +// The driver is responsible for applying migrations to the database. type Driver interface { Ping() error // Close closes the underlying db connection. If the driver is created via Open() function // this method will also going to call Close() on the sql.db instance. Close() error + // Apply should apply the migration to the database. If saveVersion is true, the driver should + // save the migration version in the database. Apply(migration *models.Migration, saveVersion bool) error + // AppliedMigrations should return a list of applied migrations. + // Ideally migrations should be sorted by version. AppliedMigrations() ([]*models.Migration, error) // SetConfig should be used to set the driver configuration. The key is the name of the configuration // This method should return an error if the key is not supported. diff --git a/drivers/lock.go b/drivers/lock.go index 9861bd3..195a2e3 100644 --- a/drivers/lock.go +++ b/drivers/lock.go @@ -63,7 +63,7 @@ func NextWaitInterval(lastWaitInterval time.Duration, err error) time.Duration { } type Locker interface { - // Lock locks m unless the context is canceled. If the mutex is already locked by any other + // Lock refreshes the lock unless the context is canceled. If the mutex is already locked by any other // instance, including the current one, the calling goroutine blocks until the mutex can be locked, // or the context is canceled. // @@ -75,10 +75,3 @@ type Locker interface { type Lockable interface { NewMutex(key string, logger Logger) (Locker, error) } - -// IsLockable returns whether the given instance satisfies -// drivers.Lockable or not. -func IsLockable(x interface{}) bool { - _, ok := x.(Lockable) - return ok -}