`UndefinedTable` error when trying to load suggested visits
Describe the bug
On the beta visits page, clicking on the suggested button triggers an ActiveRecord error:
Showing /var/app/app/views/visits/_modal.html.erb where line #20 raised:
PG::UndefinedTable: ERROR: relation "place_visits" does not exist
LINE 10: WHERE a.attrelid = '"place_visits"'::regclass
^
Trace of template inclusion: #<ActionView::Template app/views/visits/_visit.html.erb locals=["visit"]>, #<ActionView::Template app/views/visits/index.html.erb locals=[]>
Rails.root: /var/app
Version 0.14.1 via docker
To Reproduce Steps to reproduce the behavior:
- Go to
Visitspage from the navigation tab - Click on the 'Suggested' button
- See error
Expected behavior I expect to suggested visits.
Logs
From dawarich_app:
17:17:46 web.1 | D, [2024-09-20T17:17:46.542368 #86] DEBUG -- : User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
17:17:46 web.1 | D, [2024-09-20T17:17:46.542731 #86] DEBUG -- : ↳ app/controllers/application_controller.rb:11:in `unread_notifications'
17:17:46 web.1 | D, [2024-09-20T17:17:46.544550 #86] DEBUG -- : Visit Load (0.7ms) SELECT "visits".* FROM "visits" WHERE "visits"."user_id" = $1 AND "visits"."status" = $2 ORDER BY "visits"."started_at" ASC [["user_id", 1], ["status", 0]]
17:17:46 web.1 | D, [2024-09-20T17:17:46.544824 #86] DEBUG -- : ↳ app/controllers/visits_controller.rb:15:in `group_by'
17:17:46 web.1 | D, [2024-09-20T17:17:46.548022 #86] DEBUG -- : Visit Count (0.2ms) SELECT COUNT(*) FROM "visits" WHERE "visits"."user_id" = $1 AND "visits"."status" = $2 [["user_id", 1], ["status", 0]]
17:17:46 web.1 | D, [2024-09-20T17:17:46.548209 #86] DEBUG -- : ↳ app/controllers/visits_controller.rb:18:in `index'
17:17:46 web.1 | D, [2024-09-20T17:17:46.548603 #86] DEBUG -- : Rendering layout layouts/application.html.erb
17:17:46 web.1 | D, [2024-09-20T17:17:46.548630 #86] DEBUG -- : Rendering visits/index.html.erb within layouts/application
17:17:46 web.1 | I, [2024-09-20T17:17:46.551571 #86] INFO -- : {"method":"GET","path":"/visits","format":"html","controller":"VisitsController","action":"index","status":500,"allocations":9653,"duration":11.15,"view":0.0,"db":1.77}
17:17:46 web.1 | F, [2024-09-20T17:17:46.552939 #86] FATAL -- :
17:17:46 web.1 | ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "place_visits" does not exist
17:17:46 web.1 | LINE 10: WHERE a.attrelid = '"place_visits"'::regclass
17:17:46 web.1 | ^
17:17:46 web.1 | ):
17:17:46 web.1 |
17:17:46 web.1 | Causes:
17:17:46 web.1 | ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "place_visits" does not exist
17:17:46 web.1 | LINE 10: WHERE a.attrelid = '"place_visits"'::regclass
17:17:46 web.1 | ^
17:17:46 web.1 | )
17:17:46 web.1 | PG::UndefinedTable (ERROR: relation "place_visits" does not exist
17:17:46 web.1 | LINE 10: WHERE a.attrelid = '"place_visits"'::regclass
17:17:46 web.1 | ^
17:17:46 web.1 | )
17:17:46 web.1 | 17: data-api_key="<%= current_user.api_key %>"
17:17:46 web.1 | 18: data-controller="visit-modal-places"
17:17:46 web.1 | 19: data-id="<%= visit.id %>">
17:17:46 web.1 | 20: <% if visit.suggested_places.any? %>
17:17:46 web.1 | 21: <%= select_tag :place_id,
17:17:46 web.1 | 22: options_for_select(
17:17:46 web.1 | 23: visit.suggested_places.map { |place| [place.name, place.id] },
17:17:46 web.1 |
17:17:46 web.1 | D, [2024-09-20T17:17:46.553518 #86] DEBUG -- : Rendering layout vendor/bundle/ruby/3.3.0/gems/actionpack-7.2.1/lib/action_dispatch/middleware/templates/rescues/layout.erb
17:17:46 web.1 | D, [2024-09-20T17:17:46.553544 #86] DEBUG -- : Rendering vendor/bundle/ruby/3.3.0/gems/actionpack-7.2.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
17:17:46 web.1 | D, [2024-09-20T17:17:46.555291 #86] DEBUG -- : Rendering vendor/bundle/ruby/3.3.0/gems/actionpack-7.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Facing the same issue:
ActiveRecord::StatementInvalid in Visits#index
Showing /var/app/app/views/visits/_modal.html.erb where line #20 raised:
PG::UndefinedTable: ERROR: relation "place_visits" does not exist
LINE 10: WHERE a.attrelid = '"place_visits"'::regclass
^
Trace of template inclusion: #<ActionView::Template app/views/visits/_visit.html.erb locals=["visit"]>, #<ActionView::Template app/views/visits/index.html.erb locals=[]>
Rails.root: /var/app
I've fixed it on my side by executing 20240808121027_create_place_visits.rb migration again.
DELETE FROM public.schema_migrations WHERE version LIKE '20240808121027' ESCAPE '#' and restart the dawarich container.
I've fixed it on my side by executing 20240808121027_create_place_visits.rb migration again.
DELETE FROM public.schema_migrations WHERE version LIKE '20240808121027' ESCAPE '#'and restart the dawarich container.
That did the trick for me, looks like it was a missed migration in my sequence of updates. Thanks for the heads up!
I think it's no longer actual, let me know otherwise