mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* chore: add migration for pat to add default values * fix: minor changes * fix: don't panic in GetClickhouseColumnName * fix: use new function for pat * fix: address minor comments * fix: address comments * fix: remove generatepat * fix: minor changes * fix: remove extra check --------- Co-authored-by: Vibhu Pandey <vibhupandey28@gmail.com>
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package sqlmigration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/factory"
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/migrate"
|
|
)
|
|
|
|
type updatePat struct {
|
|
store sqlstore.SQLStore
|
|
}
|
|
|
|
func NewUpdatePatFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config] {
|
|
return factory.NewProviderFactory(factory.MustNewName("update_pat"), func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
|
|
return newUpdatePat(ctx, ps, c, sqlstore)
|
|
})
|
|
}
|
|
|
|
func newUpdatePat(_ context.Context, _ factory.ProviderSettings, _ Config, store sqlstore.SQLStore) (SQLMigration, error) {
|
|
return &updatePat{
|
|
store: store,
|
|
}, nil
|
|
}
|
|
|
|
func (migration *updatePat) Register(migrations *migrate.Migrations) error {
|
|
if err := migrations.Register(migration.Up, migration.Down); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *updatePat) Up(ctx context.Context, db *bun.DB) error {
|
|
|
|
// begin transaction
|
|
tx, err := db.BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
for _, column := range []string{"last_used", "expires_at"} {
|
|
if err := migration.store.Dialect().AddNotNullDefaultToColumn(ctx, tx, "personal_access_tokens", column, "INTEGER", "0"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if err := migration.store.Dialect().AddNotNullDefaultToColumn(ctx, tx, "personal_access_tokens", "revoked", "BOOLEAN", "false"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := migration.store.Dialect().AddNotNullDefaultToColumn(ctx, tx, "personal_access_tokens", "updated_by_user_id", "TEXT", "''"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *updatePat) Down(ctx context.Context, db *bun.DB) error {
|
|
return nil
|
|
}
|