TalentBox / sequel-rails

A gem for using Sequel with Rails 5.x, 6.x, 7.x, 8.x
http://talentbox.github.io/sequel-rails/
MIT License
326 stars 81 forks source link

require_valid_table = false on migrations? #139

Closed Aryk closed 7 years ago

Aryk commented 7 years ago

In order to circumvent this warning:

SEQUEL DEPRECATION WARNING: Setting a model class dataset to an invalid dataset is deprecated and will be removed in Sequel 5. Either use a valid dataset or set require_valid_table = false for the model class.

Would it make sense to automatically set

Sequel::Model.require_valid_table = false

on migrations only or give a way to do that? What would be the recommended approach? Just to do it manually in each migration?

ms-ati commented 7 years ago

Thanks, I came here via google. Can anyone shed any light on how this deprecation was intended by the authors to interact with the following rails code:

rake db:drop[test]
createdb # args for postgres
rake db:schema:load[test]

It appears that our models are loaded in the last line, triggering this warning?

JosephHalter commented 7 years ago

The way I see it, there's just never a good reason to use a model in a migration. Either manipulate the database directly or create a rake task.

ms-ati commented 7 years ago

Sorry @JosephHalter, I clarified that my issue in particular is not about migrations, to avoid that discussion which I noted on another issue. It's about loading the test database schema, which we do in our CI environment.

ms-ati commented 7 years ago

This is about the rails environment loading the model class before the database schema has been loaded.

JosephHalter commented 7 years ago

I did a quick demo project here: https://github.com/JosephHalter/demo

with nothing but rails and sequel-rails, I added a migration and a model linking to the wrong table, I'm able to run:

rake db:drop
rake db:create
rake db:schema:load

Without getting any warning.

Aryk commented 7 years ago

Got it, will go with @JosephHalter 's suggestion...

JosephHalter commented 7 years ago

@Aryk Remember that you can always create datasets without using a model by using ::Sequel::Model.db[:table_name] so you don't need to revert to SQL while still avoiding to call the model classes in the migrations.

nbulaj commented 6 years ago

@JosephHalter it works until some gem would add some models to the project that are required by default, so when you will try to run migrations - it will throw an error (because model is loaded, but table still doesn't exists).

art-solopov commented 6 years ago

It looks like required_valid_table interferes with migrations created with models.

For instance, if I run rails g model PaymentMethod and then try to run the migration, I get Sequel::DatabaseError.