How to check what prevents rake migrate?

I’m trying multisite, I have installed the second instance and it works like a charm.

But now I just can’t rebuild. The logs shows:

warning " > babel-plugin-debug-macros@0.4.0-pre1" has unmet peer dependency "@babel/core@^7.0.0".
warning "workspace-aggregator-ffab61d1-8b70-4cda-8f38-dde575adc062 > discourse > @uppy/xhr-upload@3.1.0" has inc
orrect peer dependency "@uppy/core@^3.0.6".
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "idx_category_users_user_id_category_id"
DETAIL:  Key (user_id, category_id)=(-4, 9) already exists
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Pro
cess::Status: pid 695 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.1.1/lib/pups/exec_command.rb:117:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:
migrate'"]}
bootstrap failed with exit code 1

Tried without plugins and stills broken. I can start the app but not rebuild.

Have you installed Discourse Chatbot :robot: (supporting ChatGPT) ?

Yep and tried to uninstall then (because I saw I can’t test plugins in multisite without picking them by hand).

That error is coming from it, you will need to manually fix the database record and remove the duplicates even after uninstalling a plugin as what it adds to a database is permanent.

2 Likes

Thanks. Can you please confirm if that’s what I’m looking for?

discourse=# \d category_users
                                            Table "public.category_users"
       Column       |            Type             | Collation | Nullable |                  Default                   
--------------------+-----------------------------+-----------+----------+--------------------------------------------
 id                 | integer                     |           | not null | nextval('category_users_id_seq'::regclass)
 category_id        | integer                     |           | not null | 
 user_id            | integer                     |           | not null | 
 notification_level | integer                     |           | not null | 
 last_seen_at       | timestamp without time zone |           |          | 
Indexes:
    "category_users_pkey" PRIMARY KEY, btree (id)
    "idx_category_users_category_id_user_id" UNIQUE, btree (category_id, user_id)
    "index_category_users_on_user_id_and_last_seen_at" btree (user_id, last_seen_at)

I tried DROP INDEX idx_category_users_category_id_user_id but I should really appreciate the precise command here :slight_smile:

Hmmm, presumably dozens of installs and no issues of this kind that I’m aware of.

What’s the specific problem here?

The fixtures script seeds the bot user (so the admin doesn’t need to hit the rails console) and that may fail if attempted twice but there is a check. I’ll check if the check is bomb proof. Is this running twice in this flavour of install?

You should NOT drop the index!

You just need to delete the duplicate record.

Find the second record with user_id= -4 and category_id 9 and delete it using it’s id

This is a risky operation so first check with:

SELECT FROM category_users WHERE id = <the second id>;

to ensure it just brings back one record, then:

DELETE FROM category_users WHERE id = <the second id>;

Can you recall what if any changes you made wrt to the bot?

3 Likes

Just to add I don’t think you need to remove the plugin here once this is resolved but I’m very curious why this scenario arose in the first place as had no other reports?

Thanks Robert, I asked because clearly I’m not a DB guy and I have backups BTW but it’s always better to do not deliberately the wrong :sunglasses:

The bot is not modified by me but I’m using default categories on every group and it seems to breaks your implementation.

There are more info here on Meta, I hope you can find this out and add some checkings to avoid the issue:

2 Likes

Ok so maybe not entirely my doing :sweat_smile:

2 Likes