fractaledmind / enlitenment

A Rails application template script to lead your app to SQLite enlightenment.
44 stars 3 forks source link

Thor::Error: Could not find "config/database.yml" #1

Closed thedumbtechguy closed 2 months ago

thedumbtechguy commented 2 months ago

Describe the bug This occurs immediately after running the template.

I am running a rails 7.2 application.

It fails to find my database.yml file.

It exists as expected here.

image

It added 2 gems to my Gemfile

image

To Reproduce

bin/rails app:template \
  LOCATION=https://raw.githubusercontent.com/fractaledmind/enlitenment/main/template.rb?token=****
├── config
    ├── application.rb
    ├── database.yml
    ├── puma.rb
    └── routes.rb

Expected behavior

N/A

Additional context

Output of the execution.

=> [plutonium] starting reloader
       apply  https://raw.githubusercontent.com/fractaledmind/enlitenment/main/template.rb?token=******
     gemfile    activerecord-enhancedsqlite3-adapter (~> 0.8.0)
     gemfile    solid_queue
         run    bundle install from "."
Fetching https://github.com/rails/solid_queue.git
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching et-orbi 1.2.11
Installing et-orbi 1.2.11
Fetching fugit 1.11.1
Installing fugit 1.11.1
Bundle complete! 22 Gemfile dependencies, 128 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from solid_queue:
Upgrading to Solid Queue 0.4.x? There are some breaking changes about how Solid Queue is started. Check
https://github.com/rails/solid_queue/blob/main/UPGRADING.md for upgrade instructions.
bin/rails aborted!
Rails::Generators::Error: The template [https://raw.githubusercontent.com/fractaledmind/enlitenment/main/template.rb?token=******] could not be loaded. Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are:  (Rails::Generators::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates

Caused by:
Thor::Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are:  (Thor::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates

Tasks: TOP => app:template
(See full trace by running task with --trace)
thedumbtechguy commented 2 months ago

Got it to work with this

diff --git a/template.rb b/template.rb
index 370ff35..caed642 100644
--- a/template.rb
+++ b/template.rb
@@ -92,6 +92,10 @@ class DatabaseYAML
   end
 end

+def find_in_application(path)
+  File.expand_path(Rails.root.join(path))
+end
+
 # ------------------------------------------------------------------------------

 # Ensure all SQLite connections are properly configured
@@ -115,7 +119,7 @@ unless SKIP_SOLID_QUEUE
   end

   # 3. define the new database configuration
-  database_yaml = DatabaseYAML.new path: find_in_source_paths("config/database.yml")
+  database_yaml = DatabaseYAML.new path: find_in_application("config/database.yml")
   insert_into_file "config/database.yml",
     database_yaml.new_database(QUEUE_DB) + "\n",
     after: database_yaml.database_def_regex("default"),
@@ -201,7 +205,7 @@ unless SKIP_SOLID_CACHE
   end

   # 3. define the new database configuration
-  database_yaml = DatabaseYAML.new path: find_in_source_paths("config/database.yml")
+  database_yaml = DatabaseYAML.new path: find_in_application("config/database.yml")
   insert_into_file "config/database.yml",
     database_yaml.new_database(CACHE_DB) + "\n",
     after: database_yaml.database_def_regex(QUEUE_DB)
thedumbtechguy commented 2 months ago

new diff

diff --git a/template.rb b/template.rb
index 4de1170..da8dd1f 100644
--- a/template.rb
+++ b/template.rb
@@ -92,6 +92,11 @@ class DatabaseYAML
   end
 end

+def find_in_application(path)
+  require "fileutils"
+  in_root { File.expand_path(path, FileUtils.pwd) }
+end
+
 # ------------------------------------------------------------------------------

 # Ensure all SQLite connections are properly configured
fractaledmind commented 2 months ago

I meant try this:

full_path = in_root { find_in_source_paths("config/database.yml") }
database_yaml = DatabaseYAML.new full_path
thedumbtechguy commented 2 months ago

It didn't work.

The source paths do not include the application root as listed here

Caused by:
Thor::Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are:  (Thor::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates
fractaledmind commented 2 months ago

Try simply adding readme "config/database.yml" to the script and see if that errors

thedumbtechguy commented 2 months ago
user@C02YV2TVLVCF tall_mast % bin/rails app:template \
  LOCATION=/Users/user/Desktop/enlitenment-main/template.rb
=> [plutonium] starting reloader
       apply  /Users/user/Desktop/enlitenment-main/template.rb
bin/rails aborted!
Rails::Generators::Error: The template [/Users/user/Desktop/enlitenment-main/template.rb] could not be loaded. Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are:  (Rails::Generators::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates

Caused by:
Thor::Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are:  (Thor::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates

Tasks: TOP => app:template
(See full trace by running task with --trace)
fractaledmind commented 2 months ago

And ?

in_root { readme "config/database.yml" } 

Ps. Thanks a ton for experimenting for me

thedumbtechguy commented 2 months ago

Same error

thedumbtechguy commented 2 months ago

Are you suspecting that the rails treats the app root as a source directory for templates? Does it do that on fresh install maybe?

fractaledmind commented 2 months ago

Can you add puts destination_root into the template and tell me what (if it executes) it outputs. We might need full_path = File.expand_path(path, destination_root)

fractaledmind commented 2 months ago

I am hopeful that this new commit will fix the issue. Can you give the new template a try: https://github.com/fractaledmind/enlitenment/commit/024e262931982f00979b7570722068bb1fc40ce1

thedumbtechguy commented 2 months ago

destination_root outputs the correct path.

thedumbtechguy commented 2 months ago

Confirmed that the change to destination_root fixes the problem

fractaledmind commented 2 months ago

Perfect.