Skip to content

Commit 2a2e18c

Browse files
authored
add users.avatar_url constraint and default (#1141)
1 parent 208f358 commit 2a2e18c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

app/org/maproulette/framework/repository/LeaderboardRepository.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
4444
): RowParser[LeaderboardUser] = {
4545
get[Long]("user_id") ~
4646
get[String]("user_name") ~
47-
get[String]("user_avatar_url").? ~
47+
get[String]("user_avatar_url") ~
4848
get[Int]("user_score") ~
4949
get[Int]("user_ranking") ~
5050
get[DateTime]("created").? ~
@@ -61,7 +61,7 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
6161
new LeaderboardUser(
6262
userId,
6363
name,
64-
avatarURL.getOrElse(""),
64+
avatarURL,
6565
score,
6666
rank,
6767
completedTasks,

app/org/maproulette/framework/repository/UserRepository.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ object UserRepository {
466466
get[Long]("users.id") ~
467467
get[Long]("users.osm_id") ~
468468
get[String]("users.name") ~
469-
get[Option[String]]("users.avatar_url") ~
469+
get[String]("users.avatar_url") ~
470470
get[List[Int]]("roles") map {
471471
case projectId ~ userId ~ osmId ~ displayName ~ avatarURL ~ roles =>
472-
ProjectManager(projectId, userId, osmId, displayName, avatarURL.getOrElse(""), roles)
472+
ProjectManager(projectId, userId, osmId, displayName, avatarURL, roles)
473473
}
474474
}
475475

@@ -493,7 +493,7 @@ object UserRepository {
493493
get[DateTime]("users.osm_created") ~
494494
get[String]("users.name") ~
495495
get[Option[String]]("users.description") ~
496-
get[Option[String]]("users.avatar_url") ~
496+
get[String]("users.avatar_url") ~
497497
get[Option[String]]("home") ~
498498
get[Option[String]]("users.api_key") ~
499499
get[String]("users.oauth_token") ~
@@ -544,7 +544,7 @@ object UserRepository {
544544
osmId,
545545
displayName,
546546
description.getOrElse(""),
547-
avatarURL.getOrElse(""),
547+
avatarURL,
548548
Location(locationWKT.getX, locationWKT.getY),
549549
osmCreated,
550550
oauthToken

conf/evolutions/default/95.sql

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- --- !Ups
2+
-- Update any existing null avatar_url values to the default
3+
UPDATE users
4+
SET avatar_url = '/assets/images/user_no_image.png'
5+
WHERE avatar_url IS NULL;
6+
7+
-- Alter the table to set avatar_url as NOT NULL with a default value
8+
ALTER TABLE IF EXISTS users
9+
ALTER COLUMN avatar_url SET DEFAULT '/assets/images/user_no_image.png',
10+
ALTER COLUMN avatar_url SET NOT NULL;
11+
12+
-- --- !Downs
13+
-- Revert the avatar_url column to allow null values and remove the default value
14+
ALTER TABLE IF EXISTS users
15+
ALTER COLUMN avatar_url DROP NOT NULL,
16+
ALTER COLUMN avatar_url DROP DEFAULT;

0 commit comments

Comments
 (0)