"stream_records" does not exist on production
valexl opened this issue · 6 comments
I've faced with a very weird issue. Time to time the app can't handle the requests and raises this error:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "stream_records" does not exist LINE 1: SELECT 1 AS one FROM "stream_records" WHERE "stream_records".
It looks like something random. One request is handled without any problem. The next one can raise this error. Then next attempt works well again. My main assumption right now is the order in schema_search_path
. But I can see in your examples that you force the order here - zilverline/sequent-examples@a5dcab9. Not sure how to fix that.
here is database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV["DB_POOL"] || ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: <%= ENV["DATABASE_URL"] %>
advisory_locks: <%= ENV.fetch("MIGRATION_ADVISORY_LOCKS", true) %>
prepared_statements: <%= ENV.fetch("ENABLE_PREPARED_STATEMENTS", true) %>
schema_search_path: "<%= ENV['SEQUENT_MIGRATION_SCHEMAS'] || 'public, sequent_schema, view_schema' %>"
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
I am using rails rails (7.0.4.3)
, sequent (6.0.0)
and ruby 3.2.2
.
FYI right now I went in this way:
- Add schemas for table names
config/initializers/sequent.rb
this:
Sequent::Core::EventRecord.table_name = "sequent_schema.event_records"
Sequent::Core::CommandRecord.table_name = "sequent_schema.command_records"
Sequent::Core::StreamRecord.table_name = "sequent_schema.stream_records"
- I had to use base class for read models:
class BaseRecord < Sequent::ApplicationRecord
self.abstract_class = true
def self.table_name
"view_schema.#{name.underscore.pluralize}"
end
end
- Adding schema in table_names requires changing the file names for sequent migrations:
view_schema.<table_name>.sql
That sounds weird indeed, the only time I experienced that issue is when the schema paths are messed up during running migrations (typically in development when you reset and create the database). This however was 'fixed' by providing the correct steps as described here: https://www.sequent.io/docs/rails-sequent.html
Can you double check that you are using the correct rails tasks? You can't use rails db:migrate
directly anymore for instance and need to wrap it so the search path is set correctly.
Also, make sure you use the master
branch. We haven't got into releasing yet.
Regarding rails migrations - rails schema is empty as there is no rails models so far.
The solution I described here - works. And once I start adding rails models - I have to do the same trick with adding public
schema in table name.
I still find this very strange, but can't reproduce this or have seen this occur when serving requests. If you have a reproducable example (project setup) I would be happy to take a look at it.
Unfortunately I can't reproduce that on my side. This is a fully random issue, that probably relates to rails setup. I'll let you know if I can reproduce that.
Ok, closing this issue for now. If you can reproduce let me know.