Skip to content

Commit

Permalink
fix: correct logic for descending date
Browse files Browse the repository at this point in the history
  • Loading branch information
carddev81 committed Dec 17, 2024
1 parent b05634a commit 4f737db
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit 4f737db

Please sign in to comment.