Can't restore to new site: "first_unread_topic_for" already exists with same argument types

I’m trying to restore a backup to a new site. It’s failed with this error:

[2017-05-25 21:35:33] EXCEPTION: An error has occurred, this and all later migrations canceled:

PG::DuplicateFunction: ERROR:  function "first_unread_topic_for" already exists with same argument types
:     CREATE FUNCTION first_unread_topic_for(user_id int)
    RETURNS timestamp AS
    $$
    SELECT COALESCE(first_topic_unread_at, 'epoch'::timestamp)
    FROM users u
    JOIN user_stats ON user_id = u.id
    WHERE u.id = $1
    $$
    LANGUAGE SQL STABLE
1 Like

Is this a new change from you @sam?

Looks like it. It’s in this commit.

Its a backup quirk, we don’t move the function out of the schema.

Fixed per:

https://github.com/discourse/discourse/commit/1a1f5d210137fb8360abab433ca3758e8b371331

5 Likes