4bd74af115c15806aa1e5ca60d48ee8866b22454 — Sam Whited 6 months ago 733af16 v0.0.3
Add Setup function
1 files changed, 20 insertions(+), 0 deletions(-)

A setup.go
A setup.go => setup.go +20 -0
@@ 0,0 1,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
+}