~mna/webparts

6341fae58cf26db765b63b53b000f7e0de416639 — Martin Angers 1 year, 6 months ago 75dc1e6
Remove postgres-specific migrate implementation
2 files changed, 1 insertions(+), 59 deletions(-)

M README.md
D migrate/sqlmigrate/sqlmigrate.go
M README.md => README.md +1 -0
@@ 28,3 28,4 @@ building server-based web systems and applications that are:
* `flag`: **webparts-flag**, an implementation of the flag interface with standard library's flag and envconfig (https://git.sr.ht/~mna/webparts-flag)
* `metric`: **webparts-expvar**, an implementation of the metric interface with standard library's expvar (https://git.sr.ht/~mna/webparts-expvar)
* `http/httpssn`: **webparts-sessions**, an implementation of the HTTP sessions interface with gorilla's sessions (https://git.sr.ht/~mna/webparts-sessions)
* **lundi**, a complete webparts implementation using only postgresql (https://git.sr.ht/~mna/lundi).

D migrate/sqlmigrate/sqlmigrate.go => migrate/sqlmigrate/sqlmigrate.go +0 -59
@@ 1,59 0,0 @@
//+build ignore

// TODO: move this to implementation-specific postgres version
package sqlmigrate

import (
	"context"

	"git.sr.ht/~mna/webparts/migrate"
	"git.sr.ht/~mna/webparts/sql"
)

var migrations = []migrate.Migration{
	migrate.MigrationString(`
    CREATE SCHEMA IF NOT EXISTS webparts
  `),
	migrate.MigrationString(`
    CREATE TABLE IF NOT EXISTS pgnx."migrator_versions" (
      "label"   VARCHAR(100) NOT NULL,
      "version" INTEGER NOT NULL CHECK ("version" >= 0),
      "created" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

      PRIMARY KEY ("label")
    )
  `),
}

// Migrator implements the migrate.Migrator interface for a database
// identified by the DB field.
type Migrator struct {
	DB             sql.DB
	SchemaName     string
	TableName      string
	AdvisoryLockID int

	groupMigs map[string][]migrate.Migration
	groupDeps map[string][]string
}

// Register appends migrations to the steps to apply for the specified
// group. Any dependency can be provided in the after argument and the
// union of all dependencies of the group are used to order the migrations.
func (m *Migrator) Register(ctx context.Context, group string, after []string, migrations ...migrate.Migration) error {
	if m.groupMigs == nil {
		m.groupMigs = make(map[string][]migrate.Migration)
	}
	if m.groupDeps == nil {
		m.groupDeps = make(map[string][]string)
	}
	m.groupMigs[group] = append(m.groupMigs[group], migrations...)
	m.groupDeps[group] = append(m.groupDeps[group], after...)
	return nil
}

// Migrate applies all transactions that have not been applied yet.
// Migrations are applied inside a transaction, so if supported by the
// database, any error will rollback the partially applied migrations.
func (m *Migrator) Migrate(ctx context.Context) error {
}