Closed Aryk closed 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?
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.
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.
This is about the rails environment loading the model class before the database schema has been loaded.
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.
Got it, will go with @JosephHalter 's suggestion...
@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.
@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).
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
.
In order to circumvent this warning:
Would it make sense to automatically set
on migrations only or give a way to do that? What would be the recommended approach? Just to do it manually in each migration?