feat(05-03): add user-plugin organisations table (structure only)
- create_organisations folds PHP v3.2.0; no users-table ALTER this phase - Organisation model is an FK target; app.key placeholder in config
This commit is contained in:
54
updates/organisations_test.go
Normal file
54
updates/organisations_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/lagoon"
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
)
|
||||
|
||||
func TestCreateOrganisationsMigration(t *testing.T) {
|
||||
sqlDB := dedicatedDB(t, "user_organisations")
|
||||
gdb, err := lagoon.Use(t.Context(), sqlDB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
opts := &gormigrate.Options{
|
||||
TableName: "summer_migrations_golem15_user",
|
||||
UseTransaction: true,
|
||||
}
|
||||
m := gormigrate.New(gdb, opts, All())
|
||||
if err := m.Migrate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !gdb.Migrator().HasTable("golem15_user_organisations") {
|
||||
t.Fatal("golem15_user_organisations missing after migrate")
|
||||
}
|
||||
if !gdb.Migrator().HasTable("users") {
|
||||
t.Fatal("users missing after migrate")
|
||||
}
|
||||
for _, col := range []string{"id", "slug", "name", "description", "created_at", "updated_at"} {
|
||||
if !gdb.Migrator().HasColumn("golem15_user_organisations", col) {
|
||||
t.Fatalf("missing column %s", col)
|
||||
}
|
||||
}
|
||||
|
||||
var ids []string
|
||||
if err := gdb.Raw(`SELECT id FROM summer_migrations_golem15_user ORDER BY id`).Scan(&ids).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ids) != 2 || ids[1] != "202609180002_create_organisations" {
|
||||
t.Fatalf("history = %v", ids)
|
||||
}
|
||||
|
||||
if err := m.RollbackLast(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if gdb.Migrator().HasTable("golem15_user_organisations") {
|
||||
t.Fatal("rollback must drop golem15_user_organisations")
|
||||
}
|
||||
if !gdb.Migrator().HasTable("users") {
|
||||
t.Fatal("users must survive organisations rollback")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user