Skip to content

Commit

Permalink
Fixes #24456: Missing primary key statement for user sessions table c…
Browse files Browse the repository at this point in the history
…reation when migrating
  • Loading branch information
fanf committed Mar 14, 2024
1 parent 28d4211 commit 228c36a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CheckTableUsers(
, authz text[] NOT NULL DEFAULT '{}'
, endDate timestamp with time zone
, endCause text
, PRIMARY KEY(userId, sessionId)
);"""

transactIOResult(s"Error with 'Users' table creation")(xa => sql1.update.run.transact(xa)).unit *>
Expand All @@ -93,11 +94,28 @@ class CheckTableUsers(
transactIOResult(s"Error with 'authz' column creation")(xa => sql.update.run.transact(xa)).unit
}

// In 7.0.13, we missed the primary key for usersessions
def addPrimaryKey: IOResult[Unit] = {
val sql = {
sql"""
DO $$$$ BEGIN
IF NOT EXISTS (select constraint_name from information_schema.table_constraints
where table_name = 'usersessions' and constraint_type = 'PRIMARY KEY'
) then
ALTER TABLE usersessions ADD PRIMARY KEY (userId,sessionId);
end if;
END $$$$;"""
}

transactIOResult(s"Error with primary key creation for usersessions")(xa => sql.update.run.transact(xa)).unit
}

override def checks(): Unit = {
val prog = {
for {
_ <- createUserTables
_ <- createAuthzColumn
_ <- addPrimaryKey
} yield ()
}

Expand Down

0 comments on commit 228c36a

Please sign in to comment.