New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveRecord::ConnectionAdapters::SQLite3Adapter#initialize
does not correctly create missing parent directories
#51623
Comments
@postmodern Please check this one. Seems like the actual cause of the issue. #50391 |
@maniSHarma7575 as indicated in my issue, I'm not using |
@postmodern I think it's intentional that it should raise an error when parent directory does not exists. Rails have a test case for that in source code as well.
|
@eileencodes Should we fixed this? For Sqlite3 Rails should allow to create the database even if the database path with parent directories doesn't exists? |
@maniSHarma7575 why? It does not have to raise an error, it can simply create the parent directories using |
@postmodern I also agree with you and have created a pull request for it. However, I'm unsure about the opinion of the Rails core team. Let's wait for their input and see what their take on it is. |
ActiveRecord::ConnectionAdapters::SQLite3Adapter#initialize
will check if a sqlite3 database file path exists, and if not it will attempt to create the directory usingDir.mkdir
. However,Dir.mkdir
cannot create all parent directories likeFileUtils.mkdir_p
. Thus anNo such file or directory @ dir_s_mkdir - does/not/exist/yet (Errno::ENOENT)
will be raised if one of the parent-parent directories of the sqlite3 database file do not exist yet.Steps to reproduce
ActiveRecord::Base.establish_connect({adapter: 'sqlite3', database: 'does/not/exist/yet/database.sqlite3'})
migrations = ActiveRecord::MigrationContext.new(['path/to/db/migrate'])
Your reproduction script goes here
Expected behavior
Use
FileUtils.mkdir_p
to create all parent directories for the missing sqlite3 database file.Actual behavior
System configuration
Rails version:
7.1.3.2
Ruby version:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
The text was updated successfully, but these errors were encountered: