(db sqlplugin.DB, namespace *NamespaceConfig)
| 167 | } |
| 168 | |
| 169 | func createNamespaceIfNotExists(db sqlplugin.DB, namespace *NamespaceConfig) error { |
| 170 | var ( |
| 171 | name = namespace.Detail.GetInfo().GetName() |
| 172 | id = primitives.MustParseUUID(namespace.Detail.GetInfo().GetId()) |
| 173 | ) |
| 174 | |
| 175 | // Return early if namespace already exists |
| 176 | rows, err := db.SelectFromNamespace(context.Background(), sqlplugin.NamespaceFilter{ |
| 177 | Name: &name, |
| 178 | }) |
| 179 | if err == nil && len(rows) > 0 { |
| 180 | return nil |
| 181 | } |
| 182 | |
| 183 | blob, err := serialization.NewSerializer().NamespaceDetailToBlob(namespace.Detail) |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | |
| 188 | if _, err := db.InsertIntoNamespace(context.Background(), &sqlplugin.NamespaceRow{ |
| 189 | ID: id, |
| 190 | Name: name, |
| 191 | Data: blob.GetData(), |
| 192 | DataEncoding: blob.GetEncodingType().String(), |
| 193 | IsGlobal: namespace.IsGlobal, |
| 194 | NotificationVersion: 0, |
| 195 | }); err != nil { |
| 196 | return err |
| 197 | } |
| 198 | |
| 199 | return nil |
| 200 | } |
no test coverage detected