From dda51c13dbc98c8c973e22931497a70d428edd3f Mon Sep 17 00:00:00 2001 From: carddev81 Date: Sun, 29 Dec 2024 07:31:02 -0600 Subject: [PATCH] fix: remove unused columns deleted_at and updated_at from open_content_favorites --- .../00029_alter_open_content_favorites_table.sql | 11 +++++++++++ backend/src/database/helpful_links.go | 2 +- backend/src/database/libraries.go | 3 --- backend/src/database/open_content.go | 14 +++++++------- backend/src/database/videos.go | 1 - backend/src/models/open_content.go | 11 +++++------ 6 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 backend/migrations/00029_alter_open_content_favorites_table.sql diff --git a/backend/migrations/00029_alter_open_content_favorites_table.sql b/backend/migrations/00029_alter_open_content_favorites_table.sql new file mode 100644 index 00000000..10463c8b --- /dev/null +++ b/backend/migrations/00029_alter_open_content_favorites_table.sql @@ -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 diff --git a/backend/src/database/helpful_links.go b/backend/src/database/helpful_links.go index babe47ef..b30b971c 100644 --- a/backend/src/database/helpful_links.go +++ b/backend/src/database/helpful_links.go @@ -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 diff --git a/backend/src/database/libraries.go b/backend/src/database/libraries.go index e8a2526e..ac4dec55 100644 --- a/backend/src/database/libraries.go +++ b/backend/src/database/libraries.go @@ -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) @@ -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 @@ -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 diff --git a/backend/src/database/open_content.go b/backend/src/database/open_content.go index 488736bb..ff74d72c 100644 --- a/backend/src/database/open_content.go +++ b/backend/src/database/open_content.go @@ -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 ( @@ -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 ( @@ -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 @@ -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 { @@ -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 @@ -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 @@ -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 diff --git a/backend/src/database/videos.go b/backend/src/database/videos.go index fd9a2fc4..d961c689 100644 --- a/backend/src/database/videos.go +++ b/backend/src/database/videos.go @@ -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{ diff --git a/backend/src/models/open_content.go b/backend/src/models/open_content.go index 04f5fd7e..4c4548a8 100644 --- a/backend/src/models/open_content.go +++ b/backend/src/models/open_content.go @@ -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" }