Skip to content

Commit 06edd8d

Browse files
committed
fix clerk seeding query
1 parent 621e76d commit 06edd8d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

backend/cmd/clerk/sync.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ import (
1212
"github.com/sethvargo/go-envconfig"
1313
)
1414

15+
type syncConfig struct {
16+
DB config.DB `env:",prefix=DB_"`
17+
Clerk syncClerk `env:",prefix=CLERK_"`
18+
}
19+
20+
type syncClerk struct {
21+
BaseURL string `env:"BASE_URL" envDefault:"https://api.clerk.com/v1"`
22+
SecretKey string `env:"SECRET_KEY,required"`
23+
}
24+
1525
func main() {
1626
ctx := context.Background()
17-
var cfg config.Config
27+
var cfg syncConfig
1828
if err := envconfig.Process(ctx, &cfg); err != nil {
1929
log.Fatal("failed to process config:", err)
2030
}
@@ -26,8 +36,7 @@ func main() {
2636
defer repo.Close()
2737
usersRepo := repository.NewUsersRepository(repo.DB)
2838

29-
path := "/users"
30-
err = syncUsers(ctx, cfg.BaseURL+path, cfg.SecretKey, usersRepo)
39+
err = syncUsers(ctx, cfg.Clerk.BaseURL+"/users", cfg.Clerk.SecretKey, usersRepo)
3140
if err != nil {
3241
log.Fatal(err)
3342
}

backend/internal/repository/users.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func (r *UsersRepository) BulkInsertUsers(ctx context.Context, users []*models.C
7373
INSERT INTO users (id, first_name, last_name, profile_picture)
7474
VALUES ($1, $2, $3, $4)
7575
ON CONFLICT (id) DO UPDATE
76+
SET first_name = EXCLUDED.first_name,
77+
last_name = EXCLUDED.last_name,
78+
profile_picture = EXCLUDED.profile_picture
7679
`, u.ID, u.FirstName, u.LastName, u.ProfilePicture)
7780
}
7881

0 commit comments

Comments
 (0)