1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

chore: filter on token username and user id in SQL instead (#6061)

## About the changes

Change the sorting of features to migrate created_by_user_id for, and
filter out unresolvable feature/users

Query tested manually in enterprise
This commit is contained in:
David Leek 2024-01-29 15:14:44 +01:00 committed by GitHub
parent 8a7e65eaa6
commit c08ac86c5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -740,15 +740,15 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
`LEFT OUTER JOIN ${API_TOKEN_TABLE} AS t on ev.created_by = t.username`, `LEFT OUTER JOIN ${API_TOKEN_TABLE} AS t on ev.created_by = t.username`,
) )
.whereRaw( .whereRaw(
`f.created_by_user_id IS null AND ev.type = 'feature-created'`, `f.created_by_user_id IS null AND
ev.type = 'feature-created' AND
(u.id IS NOT null OR t.username IS NOT null)`,
) )
.orderBy('f.created_at', 'asc') .orderBy('f.created_at', 'desc')
.limit(batchSize) .limit(batchSize)
.select(['f.*', 'ev.created_by', 'u.id', 't.username']); .select(['f.*', 'ev.created_by', 'u.id', 't.username']);
const updatePromises = toUpdate const updatePromises = toUpdate.map((row) => {
.filter((row) => row.id || row.username)
.map((row) => {
const id = row.id || ADMIN_TOKEN_USER.id; const id = row.id || ADMIN_TOKEN_USER.id;
return this.db(TABLE) return this.db(TABLE)