Closed thedumbtechguy closed 2 months ago
@thedumbtechguy: I just pushed a new version that should be idempotent. The test suite also has tests to ensure the template is idempotent. Please try again and let me know if things look good on your end.
confirmed! works super well now.
Noticed that migration errors are reported but don't halt the script. Is that intended?
Noticed that migration errors are reported but don't halt the script. Is that intended?
Can you give me the output?
Note: this bug is not related to your script. It's because I just rolled back all changes hence the migration failing.
The only reason I raise it is when migrations fail for some reason in the user's app, they might not notice.
Yeah, now that the script is idempotent, halting, reporting, and instructing the user to try again is indeed likely a better path. Just pushed a fix. Example expected output:
gemfile activerecord-enhancedsqlite3-adapter (~> 0.8.0)
gemfile solid_queue
def_db queue (database.yml)
add_db queue -> development (database.yml)
add_db queue -> test (database.yml)
add_db queue -> production (database.yml)
run bin/rails generate solid_queue:install from "."
error Failed to run `bin/rails generate solid_queue:install`. Resolve and try again
Golden!
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
run bundle install from "."
Bundle complete! 25 Gemfile dependencies, 133 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
def_db queue (database.yml)
run bin/rails generate solid_queue:install from "."
=> [plutonium] starting reloader
gsub config/environments/production.rb
identical config/solid_queue.yml
rails railties:install:migrations FROM=solid_queue
run bin/rails db:migrate:queue from "."
=> [plutonium] starting reloader
== 20240816091432 CreateSolidQueueTables: migrating ===========================
-- create_table(:solid_queue_jobs)
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)
SQLite3::SQLException: table "solid_queue_jobs" already exists
/Users/user/code/tall_mast/db/queue_migrate/20240816091432_create_solid_queue_tables.solid_queue.rb:4:in `change'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "solid_queue_jobs" already exists (ActiveRecord::StatementInvalid)
/Users/user/code/tall_mast/db/queue_migrate/20240816091432_create_solid_queue_tables.solid_queue.rb:4:in `change'
Caused by:
SQLite3::SQLException: table "solid_queue_jobs" already exists (SQLite3::SQLException)
/Users/user/code/tall_mast/db/queue_migrate/20240816091432_create_solid_queue_tables.solid_queue.rb:4:in `change'
Tasks: TOP => db:migrate:queue
(See full trace by running task with --trace)
error Failed to run `bin/rails db:migrate:queue`. Resolve and try again
Describe the bug Running the application multiple times results in multiple instances of duplicated config.
Additionally, there are duplicate route errors reported but they do not halt the execution of the script.
To Reproduce
Simply apply the template twice.
Expected behavior
There should be no change
Additional context
Diff
```diff diff --git a/Gemfile b/Gemfile index 5ee9f9c..cc3d217 100644 --- a/Gemfile +++ b/Gemfile @@ -66,3 +66,13 @@ gem "mission_control-jobs", "~> 0.3" gem "solid_cache", github: "rails/solid_cache", branch: "main" # Ensure all SQLite databases are backed up gem "litestream", "~> 0.10.0" +# Ensure all SQLite connections are properly configured +gem "activerecord-enhancedsqlite3-adapter", "~> 0.8.0" +# Add Solid Queue for background jobs +gem "solid_queue", github: "rails/solid_queue", branch: "main" +# Add a web UI for Solid Queue +gem "mission_control-jobs", "~> 0.3" +# Add Solid Cache as an Active Support cache store +gem "solid_cache", github: "rails/solid_cache", branch: "main" +# Ensure all SQLite databases are backed up +gem "litestream", "~> 0.10.0" diff --git a/config/application.rb b/config/application.rb index 62e4f8e..85e291a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,6 +31,14 @@ module TallMast # Ensure authorization is enabled for the Solid Queue web UI config.mission_control.jobs.base_controller_class = "ApplicationController" + # Use Solid Queue for background jobs + config.active_job.queue_adapter = :solid_queue + config.solid_queue.connects_to = { database: { writing: :queue } } + # Ensure authorization is enabled for the Solid Queue web UI + config.mission_control.jobs.base_controller_class = "ApplicationController" + # Ensure authorization is enabled for the Solid Queue web UI + config.mission_control.jobs.base_controller_class = "ApplicationController" + # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. diff --git a/config/database.yml b/config/database.yml index 3795dd7..09f5c31 100644 --- a/config/database.yml +++ b/config/database.yml @@ -25,6 +25,8 @@ development: database: storage/development.sqlite3 queue: *queue cache: *cache + queue: *queue + cache: *cache # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -35,6 +37,8 @@ test: database: storage/test.sqlite3 queue: *queue cache: *cache + queue: *queue + cache: *cache # SQLite3 write its data on the local filesystem, as such it requires @@ -49,3 +53,5 @@ production: # database: path/to/persistent/storage/production.sqlite3 queue: *queue cache: *cache + queue: *queue + cache: *cache diff --git a/config/routes.rb b/config/routes.rb index 9c33ef3..d77f4b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,8 @@ Rails.application.routes.draw do mount MissionControl::Jobs::Engine, at: "/jobs" + mount MissionControl::Jobs::Engine, at: "/jobs" + # Render dynamic PWA files from app/views/pwa/* get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker get "manifest" => "rails/pwa#manifest", as: :pwa_manifest ```Console Output
```console 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 gemfile activerecord-enhancedsqlite3-adapter (~> 0.8.0) gemfile solid_queue run bundle install from "." Your Gemfile lists the gem activerecord-enhancedsqlite3-adapter (~> 0.8.0) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Your Gemfile lists the gem solid_queue (>= 0) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Bundle complete! 27 Gemfile dependencies, 133 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. def_db queue (database.yml) add_db queue -> development (database.yml) add_db queue -> test (database.yml) add_db queue -> production (database.yml) run bin/rails generate solid_queue:install from "." => [plutonium] starting reloader gsub config/environments/production.rb identical config/solid_queue.yml rails railties:install:migrations FROM=solid_queue run bin/rails db:migrate:queue from "." => [plutonium] starting reloader insert config/application.rb unchanged config/puma.rb gemfile mission_control-jobs (~> 0.3) insert config/routes.rb insert config/application.rb gemfile solid_cache run bundle install from "." Your Gemfile lists the gem activerecord-enhancedsqlite3-adapter (~> 0.8.0) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Your Gemfile lists the gem solid_queue (>= 0) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Your Gemfile lists the gem mission_control-jobs (~> 0.3) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Your Gemfile lists the gem solid_cache (>= 0) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Bundle complete! 29 Gemfile dependencies, 133 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. def_db cache (database.yml) add_db cache -> development (database.yml) add_db cache -> test (database.yml) add_db cache -> production (database.yml) run bin/rails generate solid_cache:install from "." => [plutonium] starting reloader /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/route_set.rb:637:in `add_route': Invalid route name, already in use: 'mission_control_jobs' (ArgumentError) You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: https://guides.rubyonrails.org/routing.html#restricting-the-routes-created raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:2031:in `add_route' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:2002:in `decomposed_match' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:1966:in `block in map_match' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:1960:in `each' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:1960:in `map_match' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:1708:in `match' from /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.2.0/lib/action_dispatch/routing/mapper.rb:656:in `mount' from /Users/user/code/tall_mast/config/routes.rb:13:in `block in