Remove obsolete wiki notes
While debugging a bug from a self-managed customer #353084 (closed) I’ve noticed that we have very old (’12 and ‘13) Note
documents with noteable_type: "Wiki"
on GitLab.com. These records break scopes if you call includes(:noteable)
on it with NoMethodError: undefined method 'primary_key' for Wiki:Class
$ gdk psql
gitlabhq_development=# INSERT INTO notes (note, noteable_type, noteable_id, author_id, project_id) VALUES ('test', 'Wiki', 1, 1, 19);
INSERT 0 1
$ bin/rails c
[1] pry(main)> Note.where(id: [Note.last.id]).includes(:noteable).to_a
Note Load (0.6ms) SELECT "notes".* FROM "notes" ORDER BY "notes"."id" DESC LIMIT 1 /*application:console,db_config_name:main,line:(pry):6:in `__pry__'*/
Note Load (0.4ms) SELECT "notes".* FROM "notes" WHERE "notes"."id" = 47873 /*application:console,db_config_name:main,line:(pry):6:in `__pry__'*/
NoMethodError: undefined method `primary_key' for Wiki:Class
from /home/dgruzd/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4.6/lib/active_record/reflection.rb:307:in `primary_key'
We currently have 5 records in the production database:
gitlabhq_production=> SELECT COUNT(*) FROM "notes" WHERE "notes"."noteable_type" = 'Wiki';
count
-------
5
(1 row)
It seems that users can't see these notes in the UI and it's not clear how they were created. It isn't possible to create one using the console. It fails with a very similar exception NoMethodError: undefined method 'base_class' for Wiki:Class from /home/dgruzd/projects/gdk-ee/gitlab/app/models/note.rb:347:in 'noteable_type='
They might break other parts of the application. We should ship a background migration to remove these records from GitLab.com and self-managed instances.