signoz/pkg/sqlmigrator/sqlmigrator.go
Vibhu Pandey 268f283785
feat(sqlmigrator): add sqlmigrator package (#6836)
### Summary

- add sqlmigrator package
2025-01-17 16:52:55 +05:30

28 lines
916 B
Go

package sqlmigrator
import (
"context"
"github.com/uptrace/bun"
"github.com/uptrace/bun/migrate"
)
// SQLMigrator is the interface for the SQLMigrator.
type SQLMigrator interface {
// Migrate migrates the database. Migrate acquires a lock on the database and runs the migrations.
Migrate(context.Context) error
// Rollback rolls back the database. Rollback acquires a lock on the database and rolls back the migrations.
Rollback(context.Context) error
}
// SQLMigration is the interface for a single migration.
type SQLMigration interface {
// Register registers the migration with the given migrations. Each migration needs to be registered
//in a dedicated `*.go` file so that the correct migration semantics can be detected.
Register(*migrate.Migrations) error
// Up runs the migration.
Up(context.Context, *bun.DB) error
// Down rolls back the migration.
Down(context.Context, *bun.DB) error
}