feat: add achievement system for user gamification#3530
feat: add achievement system for user gamification#3530AmarTrebinjac wants to merge 6 commits intomainfrom
Conversation
Implements a comprehensive achievement system including: - Achievement and UserAchievement entities with database migrations - GraphQL schema for querying user achievements - Achievement progress tracking via CDC workers for various events (posts, comments, upvotes, profile updates, squads, etc.) - Notification system integration for achievement unlocks - PubSub event for achievement-unlocked notifications Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
🍹 The Update (preview) for dailydotdev/api/prod (at fc86fae) was successful. Resource Changes Name Type Operation
~ vpc-native-sync-subscription-with-cio-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tag-recommendations-cron kubernetes:batch/v1:CronJob update
~ vpc-native-calculate-top-readers-cron kubernetes:batch/v1:CronJob update
~ vpc-native-temporal-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-ws-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-generic-referral-reminder-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-stale-user-transactions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-posts-analytics-refresh-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-images-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-source-public-threshold-cron kubernetes:batch/v1:CronJob update
~ vpc-native-bg-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-user-profile-analytics-history-clickhouse-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-clickhouse-migration-6fecb4a5 kubernetes:batch/v1:Job delete
+- vpc-native-debezium-deployment kubernetes:apps/v1:Deployment create-replacement
+ vpc-native-api-db-migration-9e463a7e kubernetes:batch/v1:Job create
~ vpc-native-clean-gifted-plus-cron kubernetes:batch/v1:CronJob update
~ vpc-native-personalized-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-validate-active-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-check-analytics-report-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-source-tag-view-cron kubernetes:batch/v1:CronJob update
+ api-sub-api.achievement-unlocked-notification gcp:pubsub/subscription:Subscription create
+ vpc-native-api-clickhouse-migration-9e463a7e kubernetes:batch/v1:Job create
~ vpc-native-daily-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-highlighted-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-hourly-notification-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-history-day-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-user-companies-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-current-streak-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-private-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-clean-zombie-opportunities-cron kubernetes:batch/v1:CronJob update
~ vpc-native-expire-super-agent-trial-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-trending-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-db-migration-6fecb4a5 kubernetes:batch/v1:Job delete
+- vpc-native-debezium-props kubernetes:core/v1:Secret create-replacement
~ vpc-native-user-profile-updated-sync-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generate-search-invites-cron kubernetes:batch/v1:CronJob update
... and 4 other changes |
| where: { userId, achievementId }, | ||
| }); | ||
|
|
||
| if (!userAchievement) { |
There was a problem hiding this comment.
userAchievement ??= instead?
https://dailydotdev.slack.com/archives/C02E2C3C13R/p1769857014832369
| }) | ||
| id: string; | ||
|
|
||
| @Column({ default: () => 'now()' }) |
| }) | ||
| userId: string; | ||
|
|
||
| @Column({ default: () => 'now()' }) |
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| // Create achievement_type enum | ||
| await queryRunner.query(` | ||
| CREATE TYPE "achievement_type_enum" AS ENUM ( |
There was a problem hiding this comment.
FYI, sql side enums are a PITA to work with when they need to be updated, because you can't remove values from it, it has to be re-created
|
@claude Please consider @omBratteng feedback. Specifically about using enums in the database. It'd be better if they were regular strings in our database, and our enum type having the string as values instead. |
|
Claude finished @AmarTrebinjac's task in 1m 4s —— View job Refactoring achievement enums to use stringsI've analyzed the current implementation and found that while the entity files are correctly configured, the migration file needs to be updated to remove unused SQL ENUM types. AnalysisGood news: The TypeScript entity files are already correctly set up:
Issue: The migration
These enum types are problematic because:
Required ChangesSince migration files are protected in this repository, you'll need to manually update In the // Remove this entire section:
// Create achievement_type enum
await queryRunner.query(`
CREATE TYPE "achievement_type_enum" AS ENUM (
'instant',
'streak',
'milestone',
'multipart'
)
`);
// Create achievement_event_type enum
await queryRunner.query(`
CREATE TYPE "achievement_event_type_enum" AS ENUM (
'post_upvote',
'comment_upvote',
'bookmark_post',
'profile_image_update',
'profile_cover_update',
'profile_location_update',
'experience_work',
'experience_education',
'experience_opensource',
'experience_project',
'experience_volunteering',
'experience_skill',
'hot_take_create',
'post_share',
'post_freeform',
'squad_join',
'squad_create',
'brief_read',
'reputation_gain'
)
`);In the // Remove these lines:
// Drop enums
await queryRunner.query(`DROP TYPE "achievement_event_type_enum"`);
await queryRunner.query(`DROP TYPE "achievement_type_enum"`);After these changes:
SummaryThe entity files don't need any changes - they're already using the correct pattern. Only the migration file needs to be cleaned up to remove the unused SQL ENUM creation/deletion statements. |
Summary
Test plan
Closes ENG-558
Created by Huginn 🐦⬛