-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
29 lines (25 loc) · 809 Bytes
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package pgit
// Pgit is an instance of Pgit that is bound to a specific schema
// directory where the database schema is located and a particular
// database connection.
type Pgit struct {
db DatabaseConnection
schema *schemaDirectory
}
// New initializes and returns a new Pgit instance
func New(rootPath string, db DatabaseConnection) (*Pgit, error) {
schema, err := newSchemaDirectory(rootPath)
if err != nil {
return nil, err
}
return &Pgit{db: db, schema: schema}, nil
}
// ApplyLatest ensures the latest version of the schema has been applied
// to the database, and if not applies it.
func (p *Pgit) ApplyLatest() error {
return p.schema.applyLatest(p.db)
}
// Rollback rolls back the last migration that was applied
func (p *Pgit) Rollback() error {
return p.schema.rollback(p.db)
}