go-urlsh/migrations/20230618095614_sessioncookie_changed.go

20 lines
643 B
Go
Raw Permalink Normal View History

2024-05-04 17:06:01 +02:00
package migrations
import (
"context"
"github.com/uptrace/bun"
)
func init() {
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
db.ExecContext(context.Background(), `ALTER TABLE logins ALTER COLUMN cookie SET DATA TYPE VARCHAR`)
db.ExecContext(context.Background(), `TRUNCATE TABLE logins`)
return nil
}, func(ctx context.Context, db *bun.DB) error {
db.ExecContext(context.Background(), `ALTER TABLE logins ALTER COLUMN cookie SET DATA TYPE UUID USING (gen_random_uuid());`)
db.ExecContext(context.Background(), `ALTER TABLE logins ALTER COLUMN cookie SET DEFAULT gen_random_uuid();`)
return nil
})
}