Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal: Enhanced Logging for Migrations #266

Open
eklatzer opened this issue Jun 7, 2024 · 1 comment
Open

Feature Proposal: Enhanced Logging for Migrations #266

eklatzer opened this issue Jun 7, 2024 · 1 comment

Comments

@eklatzer
Copy link

eklatzer commented Jun 7, 2024

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.

@eklatzer
Copy link
Author

@rubenv Do you already have an info for me regarding this proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant