Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct logic for descending date #596

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/src/database/seed_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const seededActivity = "SEEDED_ACTIVITY"
func (db *DB) RunOrResetDemoSeed(facilityId uint) error {
// seeding data for demo will only seed user activity/milestones/open-content activity for existing users
activity := models.Activity{}
if err := db.Model(&models.Activity{}).Where("external_id = ?", seededActivity).Order("created_at").First(&activity).Error; err != nil {
if err := db.Model(&models.Activity{}).Where("external_id = ?", seededActivity).Order("created_at DESC").First(&activity).Error; err != nil {
return db.RunDemoSeed(facilityId)
}
if err := db.Exec("DELETE from activities where date(created_at) >= date(?)", activity.CreatedAt).Error; err != nil {
if err := db.Exec("DELETE from activities where date(created_at) <= date(?)", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "activities")
}
if err := db.Exec("DELETE from open_content_activities where date(request_ts) >= date(?)", activity.CreatedAt).Error; err != nil {
if err := db.Exec("DELETE from open_content_activities where date(request_ts) <= date(?)", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "open_content_activities")
}
if err := db.Exec("DELETE from milestones where date(created_at) >= date(?)", activity.CreatedAt).Error; err != nil {
if err := db.Exec("DELETE from milestones where date(created_at) <= date(?)", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "milestones")
}
if err := db.Exec("DELETE from outcomes where date(created_at) >= date(?)", activity.CreatedAt).Error; err != nil {
if err := db.Exec("DELETE from outcomes where date(created_at) <= date(?)", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "outcomes")
}
return db.RunDemoSeed(facilityId)
Expand Down Expand Up @@ -82,7 +82,7 @@ func (db *DB) RunDemoSeed(facilityId uint) error {
totalCourseTime := int64(0)

for day := 0; day < daysSinceStart; day++ {
randTime := rand.Int63n(50)
randTime := rand.Int63n(5000)
externalID := uuid.NewString()
if day == 0 {
externalID = "SEEDED_ACTIVITY"
Expand Down
Loading