Skip to content

Commit

Permalink
add users.avatar_url constraint and default (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak authored Aug 13, 2024
1 parent 208f358 commit 2a2e18c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
): RowParser[LeaderboardUser] = {
get[Long]("user_id") ~
get[String]("user_name") ~
get[String]("user_avatar_url").? ~
get[String]("user_avatar_url") ~
get[Int]("user_score") ~
get[Int]("user_ranking") ~
get[DateTime]("created").? ~
Expand All @@ -61,7 +61,7 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
new LeaderboardUser(
userId,
name,
avatarURL.getOrElse(""),
avatarURL,
score,
rank,
completedTasks,
Expand Down
8 changes: 4 additions & 4 deletions app/org/maproulette/framework/repository/UserRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ object UserRepository {
get[Long]("users.id") ~
get[Long]("users.osm_id") ~
get[String]("users.name") ~
get[Option[String]]("users.avatar_url") ~
get[String]("users.avatar_url") ~
get[List[Int]]("roles") map {
case projectId ~ userId ~ osmId ~ displayName ~ avatarURL ~ roles =>
ProjectManager(projectId, userId, osmId, displayName, avatarURL.getOrElse(""), roles)
ProjectManager(projectId, userId, osmId, displayName, avatarURL, roles)
}
}

Expand All @@ -493,7 +493,7 @@ object UserRepository {
get[DateTime]("users.osm_created") ~
get[String]("users.name") ~
get[Option[String]]("users.description") ~
get[Option[String]]("users.avatar_url") ~
get[String]("users.avatar_url") ~
get[Option[String]]("home") ~
get[Option[String]]("users.api_key") ~
get[String]("users.oauth_token") ~
Expand Down Expand Up @@ -544,7 +544,7 @@ object UserRepository {
osmId,
displayName,
description.getOrElse(""),
avatarURL.getOrElse(""),
avatarURL,
Location(locationWKT.getX, locationWKT.getY),
osmCreated,
oauthToken
Expand Down
16 changes: 16 additions & 0 deletions conf/evolutions/default/95.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- --- !Ups
-- Update any existing null avatar_url values to the default
UPDATE users
SET avatar_url = '/assets/images/user_no_image.png'
WHERE avatar_url IS NULL;

-- Alter the table to set avatar_url as NOT NULL with a default value
ALTER TABLE IF EXISTS users
ALTER COLUMN avatar_url SET DEFAULT '/assets/images/user_no_image.png',
ALTER COLUMN avatar_url SET NOT NULL;

-- --- !Downs
-- Revert the avatar_url column to allow null values and remove the default value
ALTER TABLE IF EXISTS users
ALTER COLUMN avatar_url DROP NOT NULL,
ALTER COLUMN avatar_url DROP DEFAULT;

0 comments on commit 2a2e18c

Please sign in to comment.