Skip to content

Commit

Permalink
chore: filter on token username and user id in SQL instead (#6061)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
daveleek authored Jan 29, 2024
1 parent 8a7e65e commit c08ac86
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib/features/feature-toggle/feature-toggle-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,21 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
`LEFT OUTER JOIN ${API_TOKEN_TABLE} AS t on ev.created_by = t.username`,
)
.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)
.select(['f.*', 'ev.created_by', 'u.id', 't.username']);

const updatePromises = toUpdate
.filter((row) => row.id || row.username)
.map((row) => {
const id = row.id || ADMIN_TOKEN_USER.id;
const updatePromises = toUpdate.map((row) => {
const id = row.id || ADMIN_TOKEN_USER.id;

return this.db(TABLE)
.update({ created_by_user_id: id })
.where({ name: row.name });
});
return this.db(TABLE)
.update({ created_by_user_id: id })
.where({ name: row.name });
});

await Promise.all(updatePromises);
}
Expand Down

0 comments on commit c08ac86

Please sign in to comment.