Use coredata models in log export batch loaders
Drop export-only row types; load Identity, PersonalAPIKey, and MembershipProfile through the usual slice LoadByIDs helpers. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -495,25 +495,7 @@ WHERE
|
||||
return nil
|
||||
}
|
||||
|
||||
type (
|
||||
MembershipProfileByUserNameRow struct {
|
||||
UserName *string `db:"user_name"`
|
||||
FullName string `db:"full_name"`
|
||||
FormattedName *string `db:"formatted_name"`
|
||||
}
|
||||
|
||||
MembershipProfileByUserNameRows []*MembershipProfileByUserNameRow
|
||||
)
|
||||
|
||||
func (p *MembershipProfileByUserNameRow) DisplayName() string {
|
||||
if p.FormattedName != nil && *p.FormattedName != "" {
|
||||
return *p.FormattedName
|
||||
}
|
||||
|
||||
return p.FullName
|
||||
}
|
||||
|
||||
func (rows *MembershipProfileByUserNameRows) LoadByOrganizationIDAndUserNames(
|
||||
func (p *MembershipProfiles) LoadByOrganizationIDAndUserNames(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
@@ -522,9 +504,40 @@ func (rows *MembershipProfileByUserNameRows) LoadByOrganizationIDAndUserNames(
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
p.user_name,
|
||||
p.id,
|
||||
p.identity_id,
|
||||
p.organization_id,
|
||||
''::citext AS email_address,
|
||||
p.source,
|
||||
p.state,
|
||||
p.full_name,
|
||||
p.formatted_name
|
||||
p.kind,
|
||||
p.additional_email_addresses,
|
||||
p.position,
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.nickname,
|
||||
p.locale,
|
||||
p.timezone,
|
||||
p.profile_url,
|
||||
p.preferred_language,
|
||||
p.given_name,
|
||||
p.family_name,
|
||||
p.formatted_name,
|
||||
p.middle_name,
|
||||
p.honorific_prefix,
|
||||
p.honorific_suffix,
|
||||
p.employee_number,
|
||||
p.department,
|
||||
p.cost_center,
|
||||
p.enterprise_organization,
|
||||
p.division,
|
||||
p.manager_value,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
iam_membership_profiles p
|
||||
WHERE
|
||||
@@ -541,17 +554,17 @@ WHERE
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rowsResult, err := conn.Query(ctx, q, args)
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query profiles by user names: %w", err)
|
||||
}
|
||||
|
||||
profiles, err := pgx.CollectRows(rowsResult, pgx.RowToAddrOfStructByName[MembershipProfileByUserNameRow])
|
||||
profiles, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MembershipProfile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect profiles by user names: %w", err)
|
||||
}
|
||||
|
||||
*rows = profiles
|
||||
*p = profiles
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user