- users.permissions and users.last_seen as additive columns - golem15_user_frontend_permissions (code, label, tab, comment) - User gains LastSeen, read-only CreatedAt and UpdatedAt and the filterByGroup list scope; none of them is serialized - migration tests roll back by position past the three new steps
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package updates
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/sm-user-plugin/models"
|
|
"git.golem15.com/golem15/summercms/modules/lagoon"
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
)
|
|
|
|
func TestAPITokenMigration(t *testing.T) {
|
|
sqlDB := dedicatedDB(t, "user_api_tokens")
|
|
db, err := lagoon.Use(t.Context(), sqlDB)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := gormigrate.New(db, &gormigrate.Options{TableName: "summer_migrations_golem15_user", UseTransaction: true}, All())
|
|
if err := m.Migrate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !db.Migrator().HasTable((&models.APIToken{}).TableName()) {
|
|
t.Fatal("user_api_tokens missing")
|
|
}
|
|
for _, column := range []string{"id", "user_id", "name", "token_hash", "scopes", "collection_ids", "expires_at", "revoked_at", "last_used_at", "last_used_ip", "oauth_client_id", "created_at", "updated_at"} {
|
|
if !db.Migrator().HasColumn(&models.APIToken{}, column) {
|
|
t.Fatalf("user_api_tokens.%s missing", column)
|
|
}
|
|
}
|
|
var oauthClientType string
|
|
if err := db.Raw(`SELECT data_type FROM information_schema.columns WHERE table_name = 'user_api_tokens' AND column_name = 'oauth_client_id'`).Scan(&oauthClientType).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if oauthClientType != "text" {
|
|
t.Fatalf("oauth_client_id type = %q, want text for legacy OAuth client IDs", oauthClientType)
|
|
}
|
|
if err := m.RollbackMigration(apiTokenMigrations[0]); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if db.Migrator().HasTable(&models.APIToken{}) {
|
|
t.Fatal("user_api_tokens survived rollback")
|
|
}
|
|
}
|