~samwhited/migration

ref: 4bd74af115c15806aa1e5ca60d48ee8866b22454 migration/setup.go -rw-r--r-- 497 bytes View raw
4bd74af1Sam Whited Add Setup function 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package migration

import (
	"context"
	"database/sql"
	"fmt"

	"github.com/lib/pq"
)

// Setup creates a migrations table with the given name.
func Setup(ctx context.Context, migrationsTable string, tx *sql.Tx) error {
	escTable := pq.QuoteIdentifier(migrationsTable)
	_, err := tx.ExecContext(ctx, fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
	version CHARACTER VARYING(50)       PRIMARY KEY,
	run_on  TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
)`, escTable))
	return err
}