rubenv / rubenv/sql-migrate

Feature Proposal: Enhanced Logging for Migrations

Open
#266 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.4k
Forks
292
PR merge metrics
No merged PRs in 30d

Description

Hey, it would be nice to be able to activate additional logging when applying migrations.
Similar requests:

I know, there is no common logger interface in Go, but what about defining a minimal one to at least get some details, especially when using sql-migrate as lib. Additionally, this could also be benefiting for the standalone tool, as there could be a new flag (e.g. --verbose).

Small example of the change: (the Logger interface definition is subject of discussion and could for example be extended to info and error or something similar):

type MigrationSet struct {
	Logger Logger
}

var migSet = MigrationSet{}

func SetLogger(l Logger) {
	if l != nil {
		migSet.Logger = l
	}
}

type Logger interface {
	Printf(format string, v ...any)
}

func (ms *MigrationSet) printf(format string, v ...any) {
	if ms.Logger == nil {
		return
	}

	ms.Logger.Printf(format, v...)
}

func Exec(migrations []string) error {
	// execute migrations
	for _, migration := range migrations {
		// apply migration

		// log additional execution info
		migSet.printf("Executing migration: %s\n", migration)
	}

	return nil
}

Please let me know, what you think about this proposal and if we can move on to a PR.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the MigrationSet and Exec entry points to understand where migrations are applied, then inspect how the standalone tool handles command-line flags. The proposal leaves the Logger interface and logging behavior open; done would require an agreed library logging API plus optional verbose output for the standalone tool.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.