-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enforce stricter model name uniqueness
- Loading branch information
Showing
4 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- 1_10.sql is a migration that enforces a stricter uniqueness | ||
-- constraint on model names. | ||
ALTER TABLE models DROP CONSTRAINT models_controller_id_owner_identity_name_name_key; | ||
ALTER TABLE models ADD CONSTRAINT unique_model_names UNIQUE(owner_identity_name, name); | ||
|
||
UPDATE versions SET major=1, minor=10 WHERE component='jimmdb'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,6 +917,24 @@ func (s *modelManagerSuite) TestCreateModel(c *gc.C) { | |
} | ||
} | ||
|
||
func (s *modelManagerSuite) TestCreateDuplicateModelsFails(c *gc.C) { | ||
conn := s.open(c, nil, "bob") | ||
defer conn.Close() | ||
createModel := func(mi jujuparams.ModelInfo) error { | ||
return conn.APICall("ModelManager", 9, "", "CreateModel", jujuparams.ModelCreateArgs{ | ||
Name: "my-model", | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
CloudTag: names.NewCloudTag(jimmtest.TestCloudName).String(), | ||
CloudCredentialTag: "cloudcred-" + jimmtest.TestCloudName + "[email protected]_cred", | ||
}, &mi) | ||
} | ||
var mi jujuparams.ModelInfo | ||
err := createModel(mi) | ||
c.Assert(err, gc.IsNil) | ||
err = createModel(mi) | ||
c.Assert(err, gc.ErrorMatches, `model bob@canonical\.com/my-model already exists \(already exists\)`) | ||
} | ||
|
||
func (s *modelManagerSuite) TestGrantAndRevokeModel(c *gc.C) { | ||
conn := s.open(c, nil, "bob") | ||
defer conn.Close() | ||
|