/
migration.go
35 lines (28 loc) · 1.01 KB
/
migration.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
30
31
32
33
34
35
// Copyright 2015 Diffeo, Inc.
// This software is released under an MIT/X11 open source license.
package postgres
import (
"database/sql"
"github.com/rubenv/sql-migrate"
)
// This file maintains the database migration code. See
// https://github.com/rubenv/sql-migrate for details of what goes in
// here. This runs "outside" the normal coordinate flow, either at
// initial startup or from an external tool.
//go:generate go-bindata -pkg postgres -o migrations.go migrations/
var migrationSource = &migrate.AssetMigrationSource{
Asset: Asset,
AssetDir: AssetDir,
Dir: "migrations",
}
// Upgrade upgrades a database to the latest database schema version.
func Upgrade(db *sql.DB) error {
_, err := migrate.Exec(db, "postgres", migrationSource, migrate.Up)
return err
}
// Drop clears a database by running all of the migrations in reverse,
// ultimately resulting in dropping all of the tables.
func Drop(db *sql.DB) error {
_, err := migrate.Exec(db, "postgres", migrationSource, migrate.Down)
return err
}