You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WHEN account_id IS NOT NULL AND TRIM(account_id) != '' THEN CONCAT('account:', TRIM(account_id))
231
+
WHEN email IS NOT NULL AND TRIM(email) != '' THEN CONCAT('email:', TRIM(email))
232
+
ELSE NULL
233
+
END
234
+
WHERE identity_key IS NULL OR TRIM(identity_key) = ''
235
+
`
236
+
default:
237
+
backfillSQL=`
238
+
UPDATE codex_quotas
239
+
SET identity_key = CASE
240
+
WHEN account_id IS NOT NULL AND TRIM(account_id) != '' THEN 'account:' || TRIM(account_id)
241
+
WHEN email IS NOT NULL AND TRIM(email) != '' THEN 'email:' || TRIM(email)
242
+
ELSE NULL
243
+
END
244
+
WHERE identity_key IS NULL OR TRIM(identity_key) = ''
245
+
`
246
+
}
247
+
iferr:=db.Exec(backfillSQL).Error; err!=nil {
248
+
returnerr
249
+
}
250
+
251
+
switchdb.Dialector.Name() {
252
+
case"mysql":
253
+
iferr:=db.Exec("DROP INDEX idx_codex_quotas_tenant_email ON codex_quotas").Error; err!=nil&&!isMySQLMissingIndexError(err) {
254
+
returnerr
255
+
}
256
+
iferr:=db.Exec("CREATE INDEX idx_codex_quotas_email ON codex_quotas(email)").Error; err!=nil&&!isMySQLDuplicateIndexError(err) {
257
+
returnerr
258
+
}
259
+
iferr:=db.Exec("CREATE UNIQUE INDEX idx_codex_quotas_tenant_identity ON codex_quotas(tenant_id, identity_key)").Error; err!=nil&&!isMySQLDuplicateIndexError(err) {
260
+
returnerr
261
+
}
262
+
default:
263
+
iferr:=db.Exec("DROP INDEX IF EXISTS idx_codex_quotas_tenant_email").Error; err!=nil {
264
+
returnerr
265
+
}
266
+
iferr:=db.Exec("CREATE INDEX IF NOT EXISTS idx_codex_quotas_email ON codex_quotas(email)").Error; err!=nil {
267
+
returnerr
268
+
}
269
+
iferr:=db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_codex_quotas_tenant_identity ON codex_quotas(tenant_id, identity_key)").Error; err!=nil {
270
+
returnerr
271
+
}
272
+
}
273
+
returnnil
274
+
},
275
+
Down: func(db*gorm.DB) error {
276
+
switchdb.Dialector.Name() {
277
+
case"mysql":
278
+
iferr:=db.Exec("DROP INDEX idx_codex_quotas_tenant_identity ON codex_quotas").Error; err!=nil&&!isMySQLMissingIndexError(err) {
279
+
returnerr
280
+
}
281
+
iferr:=db.Exec("DROP INDEX idx_codex_quotas_email ON codex_quotas").Error; err!=nil&&!isMySQLMissingIndexError(err) {
282
+
returnerr
283
+
}
284
+
iferr:=db.Exec("CREATE UNIQUE INDEX idx_codex_quotas_tenant_email ON codex_quotas(tenant_id, email)").Error; err!=nil&&!isMySQLDuplicateIndexError(err) {
285
+
returnerr
286
+
}
287
+
default:
288
+
iferr:=db.Exec("DROP INDEX IF EXISTS idx_codex_quotas_tenant_identity").Error; err!=nil {
289
+
returnerr
290
+
}
291
+
iferr:=db.Exec("DROP INDEX IF EXISTS idx_codex_quotas_email").Error; err!=nil {
292
+
returnerr
293
+
}
294
+
iferr:=db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_codex_quotas_tenant_email ON codex_quotas(tenant_id, email)").Error; err!=nil {
0 commit comments