Skip to content

Commit

Permalink
fix: remove unused columns deleted_at and updated_at from open_conten…
Browse files Browse the repository at this point in the history
…t_favorites
  • Loading branch information
carddev81 committed Dec 29, 2024
1 parent c198572 commit dda51c1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
11 changes: 11 additions & 0 deletions backend/migrations/00029_alter_open_content_favorites_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE public.open_content_favorites DROP COLUMN updated_at;
ALTER TABLE public.open_content_favorites DROP COLUMN deleted_at;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
ALTER TABLE public.open_content_favorites ADD COLUMN updated_at timestamp with time zone;
ALTER TABLE public.open_content_favorites ADD COLUMN deleted_at timestamp with time zone;
-- +goose StatementEnd
2 changes: 1 addition & 1 deletion backend/src/database/helpful_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (db *DB) GetHelpfulLinks(page, perPage int, search, orderBy string, onlyVis

subQuery := db.Table("open_content_favorites f").
Select("1").
Where("f.content_id = helpful_links.id AND f.user_id = ? AND f.deleted_at IS NULL", userID)
Where("f.content_id = helpful_links.id AND f.user_id = ?", userID)
tx := db.Model(&models.HelpfulLink{}).Select("helpful_links.*, EXISTS(?) as is_favorited", subQuery)
var total int64

Expand Down
3 changes: 0 additions & 3 deletions backend/src/database/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (db *DB) GetAllLibraries(page, perPage int, userId, facilityId uint, visibi
WHERE f.content_id = libraries.id
AND f.open_content_provider_id = libraries.open_content_provider_id
AND f.user_id = ?
AND f.deleted_at IS NULL
) AS is_favorited`, userId)

visibility = strings.ToLower(visibility)
Expand Down Expand Up @@ -65,7 +64,6 @@ func (db *DB) GetAllLibraries(page, perPage int, userId, facilityId uint, visibi
WHERE f.content_id = libraries.id
AND f.open_content_provider_id = libraries.open_content_provider_id
AND f.user_id = ?
AND f.deleted_at IS NULL
) AS is_favorited`, userId)
if !isFeatured {
tx = tx.Joins(`LEFT JOIN open_content_favorites f
Expand All @@ -84,7 +82,6 @@ func (db *DB) GetAllLibraries(page, perPage int, userId, facilityId uint, visibi
WHERE f.content_id = libraries.id
AND f.open_content_provider_id = libraries.open_content_provider_id
AND f.user_id = ?
AND f.deleted_at IS NULL
) AS is_favorited`, userId)
if !isFeatured {
tx = tx.Joins(`LEFT JOIN open_content_favorites f
Expand Down
14 changes: 7 additions & 7 deletions backend/src/database/open_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (db *DB) GetUserFavoriteGroupings(userID uint) ([]models.OpenContentItem, e
AND ocp.deleted_at IS NULL
JOIN libraries lib ON lib.open_content_provider_id = ocp.id
AND lib.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id FROM libraries where visibility_status = true)
),
ordered_videos AS (
Expand All @@ -89,7 +89,7 @@ func (db *DB) GetUserFavoriteGroupings(userID uint) ([]models.OpenContentItem, e
AND ocp.deleted_at IS NULL
JOIN videos ON videos.open_content_provider_id = ocp.id
AND videos.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id FROM videos where visibility_status = true AND availability = 'available')
),
ordered_helpful_links AS (
Expand All @@ -112,7 +112,7 @@ func (db *DB) GetUserFavoriteGroupings(userID uint) ([]models.OpenContentItem, e
AND ocp.deleted_at IS NULL
JOIN helpful_links hl ON hl.open_content_provider_id = ocp.id
AND hl.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id from helpful_links WHERE visibility_status = true)
)
SELECT
Expand Down Expand Up @@ -149,7 +149,7 @@ func (db *DB) GetUserFavorites(userID uint, page, perPage int) (int64, []models.
JOIN open_content_providers ocp ON ocp.id = lib.open_content_provider_id
AND ocp.currently_enabled = true
AND ocp.deleted_at IS NULL
WHERE fav.user_id = ? AND fav.deleted_at IS NULL
WHERE fav.user_id = ?
) AS total_favorites
`
if err := db.Raw(countQuery, userID).Scan(&total).Error; err != nil {
Expand Down Expand Up @@ -187,7 +187,7 @@ func (db *DB) GetUserFavorites(userID uint, page, perPage int) (int64, []models.
AND ocp.deleted_at IS NULL
JOIN libraries lib ON lib.open_content_provider_id = ocp.id
AND lib.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id FROM libraries where visibility_status = true)
UNION ALL
Expand All @@ -209,7 +209,7 @@ func (db *DB) GetUserFavorites(userID uint, page, perPage int) (int64, []models.
AND ocp.deleted_at IS NULL
JOIN videos ON videos.open_content_provider_id = ocp.id
AND videos.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id FROM videos where visibility_status = true AND availability = 'available')
UNION ALL
Expand All @@ -231,7 +231,7 @@ func (db *DB) GetUserFavorites(userID uint, page, perPage int) (int64, []models.
AND ocp.deleted_at IS NULL
JOIN helpful_links hl ON hl.open_content_provider_id = ocp.id
AND hl.id = f.content_id
WHERE f.user_id = ? AND f.deleted_at IS NULL
WHERE f.user_id = ?
AND f.content_id IN (SELECT id from helpful_links WHERE visibility_status = true)
) AS all_favorites
ORDER BY created_at DESC
Expand Down
1 change: 0 additions & 1 deletion backend/src/database/videos.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (db *DB) GetAllVideos(onlyVisible bool, page, perPage int, search, orderBy
WHERE f.content_id = videos.id
AND f.open_content_provider_id = videos.open_content_provider_id
AND f.user_id = ?
AND f.deleted_at IS NULL
) AS is_favorited`, userID)
var total int64
validOrder := map[string]bool{
Expand Down
11 changes: 5 additions & 6 deletions backend/src/models/open_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ type OpenContentActivity struct {
}

type OpenContentFavorite struct {
UserID uint `gorm:"not null" json:"user_id"`
ContentID uint `gorm:"not null" json:"content_id"`
OpenContentProviderID uint `gorm:"not null" json:"open_content_provider_id"`
FacilityID *uint `json:"facility_id"`
CreatedAt time.Time `json:"created_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
UserID uint `gorm:"not null" json:"user_id"`
ContentID uint `gorm:"not null" json:"content_id"`
OpenContentProviderID uint `gorm:"not null" json:"open_content_provider_id"`
FacilityID *uint `json:"facility_id"`
CreatedAt time.Time `json:"created_at"`
}

func (OpenContentActivity) TableName() string { return "open_content_activities" }
Expand Down

0 comments on commit dda51c1

Please sign in to comment.