From bceb4cfe24b788dfcbb43d4c55f00b7931106aba Mon Sep 17 00:00:00 2001 From: Joseph Spurrier Date: Sat, 12 Jan 2019 13:05:04 -0500 Subject: [PATCH] Remove exec parameters Closes #15 --- README.md | 30 +++++++++++++++++++++++++++++ interface.go | 19 +++++++++--------- pkg/adapter/jsonfile/jsonfile.go | 14 ++++++-------- pkg/adapter/jsonfile/transaction.go | 3 ++- pkg/adapter/mysql/mysql.go | 7 +++---- pkg/adapter/mysql/transaction.go | 4 ++-- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a6256a3..aaaff9f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/interface.go b/interface.go index eed591b..07afa9f 100644 --- a/interface.go +++ b/interface.go @@ -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. @@ -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 @@ -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 } diff --git a/pkg/adapter/jsonfile/jsonfile.go b/pkg/adapter/jsonfile/jsonfile.go index 9d5ee4a..dcdecd9 100644 --- a/pkg/adapter/jsonfile/jsonfile.go +++ b/pkg/adapter/jsonfile/jsonfile.go @@ -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, }) } } diff --git a/pkg/adapter/jsonfile/transaction.go b/pkg/adapter/jsonfile/transaction.go index 6f90168..c870f7f 100644 --- a/pkg/adapter/jsonfile/transaction.go +++ b/pkg/adapter/jsonfile/transaction.go @@ -1,5 +1,6 @@ package jsonfile +/* import ( "fmt" "io/ioutil" @@ -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 -} +}*/ diff --git a/pkg/adapter/mysql/mysql.go b/pkg/adapter/mysql/mysql.go index 4c66596..9e8bb6e 100644 --- a/pkg/adapter/mysql/mysql.go +++ b/pkg/adapter/mysql/mysql.go @@ -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, }) } diff --git a/pkg/adapter/mysql/transaction.go b/pkg/adapter/mysql/transaction.go index d997a22..fc4c6d1 100644 --- a/pkg/adapter/mysql/transaction.go +++ b/pkg/adapter/mysql/transaction.go @@ -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 }