fix mysql tenant database schema cleanup
This commit is contained in:
@@ -658,7 +658,6 @@ func (a *adapter) CreateDb(reset bool) error {
|
||||
if _, err = tx.Exec(
|
||||
`CREATE TABLE auth(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
uname VARCHAR(32) NOT NULL,
|
||||
userid BIGINT NOT NULL,
|
||||
scheme VARCHAR(16) NOT NULL,
|
||||
@@ -836,7 +835,6 @@ func (a *adapter) CreateDb(reset bool) error {
|
||||
if _, err = tx.Exec(
|
||||
`CREATE TABLE credentials(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
createdat DATETIME(3) NOT NULL,
|
||||
updatedat DATETIME(3) NOT NULL,
|
||||
deletedat DATETIME(3),
|
||||
|
||||
+18
-5
@@ -105,15 +105,28 @@ func TestDispatchHello(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchHelloRequiresTenant(t *testing.T) {
|
||||
func TestDispatchHelloDefaultsTenant(t *testing.T) {
|
||||
oldTenants := store.Tenants
|
||||
store.Tenants = testTenantStore{tenant: &types.Tenant{
|
||||
ID: 1,
|
||||
Code: "default",
|
||||
Name: "Default Tenant",
|
||||
State: types.TenantStateActive,
|
||||
}}
|
||||
defer func() { store.Tenants = oldTenants }()
|
||||
|
||||
s := &Session{send: make(chan any, 1)}
|
||||
s.dispatch(&ClientComMessage{Hi: &MsgClientHi{Id: "123", Version: "1"}})
|
||||
resp := (<-s.send).(*ServerComMessage)
|
||||
if resp.Ctrl.Code != http.StatusBadRequest {
|
||||
t.Fatalf("response code: expected %d, got %d", http.StatusBadRequest, resp.Ctrl.Code)
|
||||
if resp.Ctrl.Code != http.StatusCreated {
|
||||
t.Fatalf("response code: expected %d, got %d", http.StatusCreated, resp.Ctrl.Code)
|
||||
}
|
||||
if !s.tenantID.IsZero() || s.ver != 0 {
|
||||
t.Fatalf("invalid hello must not bind session: tenant=%d version=%d", s.tenantID, s.ver)
|
||||
if s.tenantID != 1 || s.tenantCode != "default" || s.ver == 0 {
|
||||
t.Fatalf("default hello did not bind session: tenant=%d code=%q version=%d", s.tenantID, s.tenantCode, s.ver)
|
||||
}
|
||||
tenantParams := resp.Ctrl.Params.(map[string]any)["tenant"].(map[string]any)
|
||||
if tenantParams["code"] != "default" || tenantParams["name"] != "Default Tenant" {
|
||||
t.Fatalf("unexpected tenant params: %#v", tenantParams)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user