parent
34c9a053dd
commit
84803a41a1
14
meta/data.go
14
meta/data.go
|
@ -195,25 +195,13 @@ func (data *Data) RenameDatabase(oldName, newName string) error {
|
|||
for i := range data.Databases {
|
||||
if data.Databases[i].Name == oldName {
|
||||
data.Databases[i].Name = newName
|
||||
data.switchDatabaseUserPrivileges(oldName, newName)
|
||||
// TODO should rename the databases used in continuous queries
|
||||
//TODO CQs
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrDatabaseNotFound
|
||||
}
|
||||
|
||||
// switchDatabaseUserPrivileges changes the database associated with user privileges
|
||||
func (data *Data) switchDatabaseUserPrivileges(oldDatabase, newDatabase string) error {
|
||||
for i := range data.Users {
|
||||
if p, ok := data.Users[i].Privileges[oldDatabase]; ok {
|
||||
data.Users[i].Privileges[newDatabase] = p
|
||||
delete(data.Users[i].Privileges, oldDatabase)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RetentionPolicy returns a retention policy for a database by name.
|
||||
func (data *Data) RetentionPolicy(database, name string) (*RetentionPolicyInfo, error) {
|
||||
di := data.Database(database)
|
||||
|
|
|
@ -151,35 +151,6 @@ func TestData_RenameDatabase(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure that user privileges are updated correctly when database is renamed.
|
||||
func TestData_RenameDatabaseUpdatesPrivileges(t *testing.T) {
|
||||
var data meta.Data
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
data.Users = []meta.UserInfo{{
|
||||
Name: "susy",
|
||||
Hash: "ABC123",
|
||||
Admin: true,
|
||||
Privileges: map[string]influxql.Privilege{
|
||||
"db1": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}
|
||||
|
||||
if err := data.RenameDatabase("db1", "db2"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(data.Users,
|
||||
[]meta.UserInfo{{
|
||||
Name: "susy",
|
||||
Hash: "ABC123",
|
||||
Admin: true,
|
||||
Privileges: map[string]influxql.Privilege{
|
||||
"db2": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}) {
|
||||
t.Fatalf("unexpected user privileges: %#v", data.Users)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that renaming a database without both old and new names returns an error.
|
||||
func TestData_RenameDatabase_ErrNameRequired(t *testing.T) {
|
||||
var data meta.Data
|
||||
|
|
Loading…
Reference in New Issue