Applied migrations we shouldn't have with discourse-ai

AI-generated summary

Cédric_Brunet encountered an issue with the Jobs::EmbeddingsBackfill job failing due to missing tables like ai_topic_embeddings_8_1, despite migrations appearing to be applied. The problem arose from applying migrations that shouldn’t have been executed, likely due to using an incorrect plugin version. The migrations listed as ********** NO FILE ********** in rake db:migrate:status indicate missing migration files, suggesting the wrong plugin version was used. Cédric_Brunet realized the issue and resolved it by manually reverting the migrations using SQL, deleting entries from schema_migrations and removing the problematic migration files. Cédric_Brunet advises others to locate the correct migration files on the plugin’s GitHub repository and manually rollback using SQL if needed.

Hi,

We are using discourse 3.3.0, and i have the job Jobs::EmbeddingsBackfill which fails with :
Job exception: PG::UndefinedTable: ERROR: relation "ai_topic_embeddings_8_1" does not exist

I can see i have the table “ai_topic_embeddings”, but none of the ai_topic_embeddings_8_1, ai_topic_embeddings_6_1…

When running rake db:migrate:status i can see the migrations are up, and most of the ai features are working.

Any idea on what went wrong ?

Just saw there’s a migration called 20240611170905_move_embeddings_to_single_table_per_type
which indicate that we applied migrations we shouldn’t have by using the wrong plugin version.

I have multiple migrations like this, which refer to the one that shouldn’t be done i think :
up 20240807150605 ********** NO FILE **********
up 20240809162837 ********** NO FILE **********
up 20240809163303 ********** NO FILE **********

Is there a way to rollback them ? If there’s a way to just remove everything from discourse-ai on my instance and start fresh that’s good too

Managed to fix my problem by reverting the migrations manualy with sql.

For anyone doing the same mistake, after you set the plugin to the right commit, execute this : rake db:migrate:status
this will show you lines without files : up 20240809163303 ********** NO FILE **********
for each of them find the associated migration file on the plugin github (try to search on the whole discourse org so it’s faster)
then if there’s no down option, just remove it from sql : delete from schema_migrations where version = '........'; and rollback it manualy with sql