Skip to content

Commit

Permalink
Remove exec parameters
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
josephspurrier committed Jan 12, 2019
1 parent 2210274 commit bceb4cf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,36 @@ Rove is designed to be extensible via adapters. There are a few adapters built i

You may also create your own adapters - see the `interface.go` file for interfaces your adapters must satisfy.

### Best Practices

When creating an adapter, will need:

- Struct that satisfies the `rove.Changelog` interface.
- Struct that satisfies the `rove.Transaction` interface.
- Table or data structure called a `Changelog` to persistently track the changes made by the Rove.

You should store the following fields (at a minimum) in your changelog. This will ensure your adapter can utilize all of the features of Rove.

- id
- author
- filename
- dataexecuted
- orderexecuted
- checksum
- description
- tag
- version

### Example Changelog

Your changelog should look contain the same data as this table:

| id | author | filename | dateexecuted | orderexecuted | checksum | description | tag | version |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | josephspurrier | success.sql | 2019-01-12 16:04:16 | 1 | f0685b... | Create the user_status table. | NULL | 1.0 |
| 2 | josephspurrier | success.sql | 2019-01-12 16:04:16 | 2 | 3f81b0... | | NULL | 1.0 |
| 3 | josephspurrier | success.sql | 2019-01-12 16:04:16 | 3 | 57cc0b... | | NULL | 1.0 |

## Migration File Specifications

There are a few components of a changeset:
Expand Down
19 changes: 9 additions & 10 deletions interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package rove

// Changelog represents a list of operations that can be run on a changelog.
// Changelog represents a list of operations for a changelog.
type Changelog interface {
// Initialize should perform any work to set up the changelog or return an
// error.
Expand All @@ -22,14 +22,6 @@ type Changelog interface {
Delete(id, author, filename string) error
}

// Changeset is a single changeset.
type Changeset struct {
ID string
Author string
Filename string
OrderExecuted int
}

// Transaction represents a changelog transaction.
type Transaction interface {
// Commit should attempt to commit the changes to to the changelog or
Expand All @@ -38,5 +30,12 @@ type Transaction interface {
// Rollback should undo changes to the changelog after a failed commit.
Rollback() error
// Exec should prepare to make a change to the changelog.
Exec(query string, args ...interface{}) error
Exec(query string) error
}

// Changeset is a single changeset.
type Changeset struct {
ID string
Author string
Filename string
}
14 changes: 6 additions & 8 deletions pkg/adapter/jsonfile/jsonfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ func (m *Info) Changesets(reverse bool) ([]rove.Changeset, error) {
for _, i := range results {
if reverse {
out = append([]rove.Changeset{{
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
OrderExecuted: i.OrderExecuted,
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
}}, out...)
} else {
out = append(out, rove.Changeset{
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
OrderExecuted: i.OrderExecuted,
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/adapter/jsonfile/transaction.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jsonfile

/*
import (
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -32,4 +33,4 @@ func (t *Transaction) Rollback() error {
func (t *Transaction) Exec(query string, args ...interface{}) error {
t.data = fmt.Sprintf(query, args...)
return nil
}
}*/
7 changes: 3 additions & 4 deletions pkg/adapter/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ func (m *MySQL) Changesets(reverse bool) ([]rove.Changeset, error) {
out := make([]rove.Changeset, 0)
for _, i := range results {
out = append(out, rove.Changeset{
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
OrderExecuted: i.OrderExecuted,
Author: i.Author,
Filename: i.Filename,
ID: i.ID,
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/adapter/mysql/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (t *Tx) Rollback() error {
}

// Exec will run a query on the database.
func (t *Tx) Exec(query string, args ...interface{}) error {
_, err := t.db.Exec(query, args...)
func (t *Tx) Exec(query string) error {
_, err := t.db.Exec(query)
return err
}

0 comments on commit bceb4cf

Please sign in to comment.