NewNamespaceConfig initializes a NamespaceConfig with the field values needed to pre-register the namespace via the CreateNamespaces function. Note: this function may receive breaking changes or be removed in the future.
( activeClusterName string, namespace string, global bool, customSearchAttributes map[string]enumspb.IndexedValueType, )
| 111 | // |
| 112 | // Note: this function may receive breaking changes or be removed in the future. |
| 113 | func NewNamespaceConfig( |
| 114 | activeClusterName string, |
| 115 | namespace string, |
| 116 | global bool, |
| 117 | customSearchAttributes map[string]enumspb.IndexedValueType, |
| 118 | ) (*NamespaceConfig, error) { |
| 119 | dbCustomSearchAttributes := sadefs.GetDBIndexSearchAttributes(nil).CustomSearchAttributes |
| 120 | fieldToAliasMap := map[string]string{} |
| 121 | for saName, saType := range customSearchAttributes { |
| 122 | var targetFieldName string |
| 123 | var cntUsed int |
| 124 | for fieldName, fieldType := range dbCustomSearchAttributes { |
| 125 | if fieldType != saType { |
| 126 | continue |
| 127 | } |
| 128 | if _, ok := fieldToAliasMap[fieldName]; !ok { |
| 129 | targetFieldName = fieldName |
| 130 | break |
| 131 | } |
| 132 | cntUsed++ |
| 133 | } |
| 134 | if targetFieldName == "" { |
| 135 | return nil, fmt.Errorf( |
| 136 | "cannot have more than %d search attributes of type %s", |
| 137 | cntUsed, |
| 138 | saType, |
| 139 | ) |
| 140 | } |
| 141 | fieldToAliasMap[targetFieldName] = saName |
| 142 | } |
| 143 | |
| 144 | detail := persistencespb.NamespaceDetail{ |
| 145 | Info: &persistencespb.NamespaceInfo{ |
| 146 | Id: primitives.NewUUID().String(), |
| 147 | State: enumspb.NAMESPACE_STATE_REGISTERED, |
| 148 | Name: namespace, |
| 149 | }, |
| 150 | Config: &persistencespb.NamespaceConfig{ |
| 151 | Retention: timestamp.DurationFromHours(24), |
| 152 | HistoryArchivalState: enumspb.ARCHIVAL_STATE_DISABLED, |
| 153 | VisibilityArchivalState: enumspb.ARCHIVAL_STATE_DISABLED, |
| 154 | CustomSearchAttributeAliases: fieldToAliasMap, |
| 155 | }, |
| 156 | ReplicationConfig: &persistencespb.NamespaceReplicationConfig{ |
| 157 | ActiveClusterName: activeClusterName, |
| 158 | Clusters: []string{activeClusterName}, |
| 159 | }, |
| 160 | FailoverVersion: common.EmptyVersion, |
| 161 | FailoverNotificationVersion: -1, |
| 162 | } |
| 163 | return &NamespaceConfig{ |
| 164 | Detail: &detail, |
| 165 | IsGlobal: global, |
| 166 | }, nil |
| 167 | } |
| 168 | |
| 169 | func createNamespaceIfNotExists(db sqlplugin.DB, namespace *NamespaceConfig) error { |
| 170 | var ( |
no test coverage detected