mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 16:10:03 +01:00
Implement rollback command
This commit is contained in:
parent
ece5d3cf0e
commit
1c4cf2c122
4 changed files with 138 additions and 25 deletions
|
|
@ -14,7 +14,7 @@ type Driver interface {
|
|||
CreateDatabase(*url.URL) error
|
||||
DropDatabase(*url.URL) error
|
||||
CreateMigrationsTable(*sql.DB) error
|
||||
SelectMigrations(*sql.DB) (map[string]struct{}, error)
|
||||
SelectMigrations(*sql.DB, int) (map[string]struct{}, error)
|
||||
InsertMigration(shared.Transaction, string) error
|
||||
DeleteMigration(shared.Transaction, string) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,13 @@ func (postgres Driver) CreateMigrationsTable(db *sql.DB) error {
|
|||
}
|
||||
|
||||
// SelectMigrations returns a list of applied migrations
|
||||
func (postgres Driver) SelectMigrations(db *sql.DB) (map[string]struct{}, error) {
|
||||
rows, err := db.Query("SELECT version FROM schema_migrations")
|
||||
// with an optional limit (in descending order)
|
||||
func (postgres Driver) SelectMigrations(db *sql.DB, limit int) (map[string]struct{}, error) {
|
||||
query := "SELECT version FROM schema_migrations ORDER BY version DESC"
|
||||
if limit >= 0 {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, limit)
|
||||
}
|
||||
rows, err := db.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue