ilyakatz / data-migrate

Migrate and update data alongside your database structure.
MIT License
1.42k stars 194 forks source link

Error on data:schema:load in v9.1.0 #280

Closed adelnabiullin closed 1 year ago

adelnabiullin commented 1 year ago

rake data:schema:load and rake db:schema:load:with_data raise errors in v9.1.0 (works fine with v9.0.0).

Error examples:

$ rails data:schema:load
rails aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /<repo_path>/db/schema.rb
/<repo_path>/bin/rails:9:in `<top (required)>'
/<repo_path>/bin/spring:12:in `block in <top (required)>'
/<repo_path>/bin/spring:9:in `<top (required)>'
Tasks: TOP => data:schema:load
(See full trace by running task with --trace)
$ rails db:schema:load:with_data
Running via Spring preloader in process 57714
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /<repo_path>/db/schema.rb
<internal:/Users/<username>/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/Users/<username>/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
-e:1:in `<main>'
Tasks: TOP => db:schema:load:with_data
(See full trace by running task with --trace)

Also tried db:structure:load:with_data, it does not recognise the command (with both 9.0.0 and 9.1.0 versions of data_migrate gem):

$ rails db:structure:load:with_data
Running via Spring preloader in process 58409
rake aborted!
Don't know how to build task 'db:structure:load' (See the list of available tasks with `rake --tasks`)
Did you mean?  db:structure:load:with_data
<internal:/Users/<username>/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/Users/<username>/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
-e:1:in `<main>'
Tasks: TOP => db:structure:load:with_data
(See full trace by running task with --trace)

System:

ruby 3.2.2p53
rails 7.0.6
MacOS 12.1 (arm64)
wildmaples commented 1 year ago

Hi @adelnabiullin - thanks for reporting this issue!

I suspect that there are two different issues you've discovered:

  1. Errno::ENOENT: No such file or directory @ rb_sysopen error - I can't reproduce this issue but it could be related to this change. Do you have a db/schema.rb directory/file? It seems like the two tasks are complaining that you don't have it. Could you also try running the commands --trace option and sharing the trace?

  2. Don't know how to build task 'db:structure:load' - this is due to Rails removing the deprecated task db:structure:load in Rails 7.0 (which is probably why you see it in both 9.0.0 and 9.1.0 of the gem). Since db:structure:load:with_data invokes the removed task, we see that error.

ngan commented 1 year ago

@adelnabiullin we just released 9.1.1 that should address this. Can you give it a try?

adelnabiullin commented 1 year ago

@ngan it works with 9.1.1, thanks 👍🏻

Judahmeek commented 7 months ago

I'm seeing

Don't know how to build task 'db:structure:load' (See the list of available tasks with `rake --tasks`)
Did you mean?  db:structure:load:with_data

with version 9.3.0.

Also seeing it with version 9.1.1.

The error location is different than OP's, however: /tasks/databases.rake:184

Adding a monkey patch:

namespace :db do
  namespace :structure do
    desc "monkey patch for task deprecated in Rails 7"
    task :load do
    end
  end
end

resolved this issue for me.