signoz/pkg/sqlmigration/sqlmigration.go
Vibhu Pandey 9e449e2858
feat(auth): drop group table (#7672)
### Summary

drop group table
2025-04-26 15:50:02 +05:30

68 lines
1.5 KiB
Go

package sqlmigration
import (
"context"
"errors"
"github.com/SigNoz/signoz/pkg/factory"
"github.com/uptrace/bun"
"github.com/uptrace/bun/migrate"
)
// 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
}
var (
ErrNoExecute = errors.New("no execute")
)
var (
OrgReference = "org"
UserReference = "user"
CloudIntegrationReference = "cloud_integration"
)
func New(
ctx context.Context,
settings factory.ProviderSettings,
config Config,
factories factory.NamedMap[factory.ProviderFactory[SQLMigration, Config]],
) (*migrate.Migrations, error) {
migrations := migrate.NewMigrations()
for _, factory := range factories.GetInOrder() {
migration, err := factory.New(ctx, settings, config)
if err != nil {
return nil, err
}
err = migration.Register(migrations)
if err != nil {
return nil, err
}
}
return migrations, nil
}
func MustNew(
ctx context.Context,
settings factory.ProviderSettings,
config Config,
factories factory.NamedMap[factory.ProviderFactory[SQLMigration, Config]],
) *migrate.Migrations {
migrations, err := New(ctx, settings, config, factories)
if err != nil {
panic(err)
}
return migrations
}