Thank you very much, Jeremy! In the end, I needed to always set 
require_valid_table to false in the Heroku environment, due to multiple 
application boots. For completeness, I ended up with the following commit 
in my repo:

commit 380b382f684c19216e580b37e515ca206a2b15f3 (HEAD -> main, heroku/main)
Author: François Beausoleil <[email protected]>
Date:   Wed Oct 14 22:37:00 2020 -0400

    Prevent error during Heroku deployment related to asset precompilation

    Heroku runs asset precompilation before running migrations. When
    Sequel::Model classes are loaded in memory, they immediately attempt to
    read their table schema. Since the table does not yet exist in the
    database, PG raises an exception, which prevents asset precompilation.

    Following a suggestion from Jeremy Evans, the maintainer of Sequel,
    ignore errors related to the model attempting to read its table.

diff --git a/lib/tasks/fix_migration_precompilation.rake 
b/lib/tasks/fix_migration_precompilation.rake
new file mode 100644
index 0000000..b8a54f9
--- /dev/null
+++ b/lib/tasks/fix_migration_precompilation.rake
@@ -0,0 +1,7 @@
+if ENV["RAILS_LOG_TO_STDOUT"] == "enabled"
+  warn 
"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*"
+  warn "Presuming we are running on Herou due to RAILS_LOG_TO_STDOUT being 
set"
+  warn "Turning off Sequel::Model.require_valid_table due to 
https://groups.google.com/g/sequel-talk/c/prHYu48GK8A";
+  warn 
"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*"
+  Sequel::Model.require_valid_table = false
+end

I hope this helps someone in the future.

Cheers!
François

Le mercredi 14 octobre 2020 à 18 h 20 min 11 s UTC-4, Jeremy Evans a écrit :

> On Wed, Oct 14, 2020 at 2:50 PM François Beausoleil <
> [email protected]> wrote:
>
>> Hi all!
>>
>> Detailed version info at the bottom.
>>
>> On a new app, I'm trying sequel-rails. It seems that Sequel::Model 
>> classes eagerly attempt to read their table schema. This prevents 
>> deployment to Heroku as asset precompilation happens before migrations, and 
>> asset precompilation must boot the app.
>>
>> The order of operations seems to be similar to the following:
>>
>> bin/rails g model person name:text
>> bin/rails db:migrate
>> git add --all
>> git commit --message "Person model"
>> git push heroku
>>     - bin/rails assets:precompile
>>         - Rails eagerly loads models, because RAILS_ENV=production
>>         - Person attempts to read the table schema
>>         - PG correctly raises an exception, as the table does not exist
>>
>> I did define release in my Procfile, but migrations are run after asset 
>> precompilation.
>>
>> As a test, I changed config/environments/production.rb to set eager_load 
>> to false, alas, to no effect.
>>
>> I searched this group's archive with "sequel model eager load schema", 
>> but that only matched release announcements. DuckDuckGo also returns a 
>> bunch of results about Sequelize, EntityFramework and other tools. The 
>> search terms are probably too generic. I read the Sequel::Model 
>> documentation as well, but didn't find anything that seemed relevant.
>>
>> Is there a way to tell Sequel::Model instances to delay trying to read 
>> the schema? Failing that, would you have other workarounds?
>>
>
> You can try Sequel::Model.require_valid_table = false before loading your 
> model classes, at least when you are doing asset precompilation.  That 
> doesn't make the classes lazy load, that just ignores errors.  That may be 
> an acceptable work around.  A better solution would be fixing Rails so it 
> runs migrations before asset precompilation, or make asset precompilation 
> not load the models.
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/009af91a-bb44-4206-952c-a194e7956297n%40googlegroups.com.

Reply via email to