We are working on rails engine on 3.2.9. Engine is generated with :
rails plugin new rails_engine -mountable --skip-test-unit --dummy-path=spec/dummy
After initial setup, we can generate a model just like what we do in regular rails app:
rails g model post name:string
There is a migration file created under db/migrate/. Next we did db:migrate under the/ rails_engine :
rake db:migrate
It causes error:
Don't know how to build task 'db:migrate'
List available rake tasks:
bundle exec rake --tasks
rake build # Build test_itemx-0.0.1.gem into the pkg directory
rake clobber_rdoc # Remove RDoc HTML files
rake install # Build and install test_itemx-0.0.1.gem into system gems
rake rdoc # Build RDoc HTML files
rake release # Create tag v0.0.1 and build and push test_itemx-0.0.1.gem to Rubygems
rake rerdoc # Rebuild RDoc HTML files
There is no db:migrate among them. The question is how to load db tasks back to rake.
This is the expected behavior. Remember that it is a mountable engine. It does not have an environment of it's own. You need to mount it to a Rails application (Not an engine but an actual app). Engine does not have any database. It uses the database defined in its parent app in which it is mounted. So obviously your db:migrate would not work.
Do the following in your parent app for an engine:
Mount your engine in the Gemfile of a rails application as just another engine using :path or :git option
gem 'engine_name', :path=>'path/to/engine/directory'
bundle install
rake engine_name:install:migrations
rake db:migrate
I've entered spec/dummy in my engine folder and just runned rake db:migrate plus the same for test Env, and db/schema.rb was added.
But I had to add spec/dummy/db folder manually before.
Related
I can't execute rake routes even if the routes.rb file is empty. This is the output:
➜ rake routes
rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)
(See full trace by running task with --trace)
Output from rake about:
➜ rake about
About your application's environment
Rails version 6.1.0
Ruby version ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
RubyGems version 3.1.4
Rack version 2.2.3
Middleware Webpacker::DevServerProxy, Rack::MiniProfiler, ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, ActionDispatch::PermissionsPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper, Warden::Manager
Application root /Users/cobexa/app
Environment development
Database adapter postgresql
Database schema version 20201219225707
And output from rake --tasks:
rake about # List versions of all Rails frameworks and the environment
rake action_mailbox:ingress:exim # Relay an inbound email from Exim to Action Mailbox (URL and INGRESS_PASSWORD required)
rake action_mailbox:ingress:postfix # Relay an inbound email from Postfix to Action Mailbox (URL and INGRESS_PASSWORD required)
rake action_mailbox:ingress:qmail # Relay an inbound email from Qmail to Action Mailbox (URL and INGRESS_PASSWORD required)
rake action_mailbox:install # Installs Action Mailbox and its dependencies
rake action_mailbox:install:migrations # Copy migrations from action_mailbox to application
rake action_text:install # Copy over the migration, stylesheet, and JavaScript files
rake action_text:install:migrations # Copy migrations from action_text to application
rake active_storage:install # Copy over the migration needed to the application
rake app:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake app:update # Update configs and some other initially generated files (or use just update:configs or update:bin)
rake assets:clean[keep] # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:environment # Load asset compile environment
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases, except when DATABASE_URL is present
rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases, except when DATABASE_URL is present
rake db:environment:set # Set the environment value for the database
rake db:fixtures:load # Loads fixtures into the current environment's database
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake db:migrate:down # Runs the "down" for a given migration VERSION
rake db:migrate:redo # Rolls back the database one migration and re-migrates up (options: STEP=x, VERSION=x)
rake db:migrate:status # Display status of migrations
rake db:migrate:up # Runs the "up" for a given migration VERSION
rake db:prepare # Runs setup if database does not exist, or runs migrations if it does
rake db:reset # Drops and recreates the database from db/schema.rb for the current environment and loads the seeds
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:cache:clear # Clears a db/schema_cache.yml file
rake db:schema:cache:dump # Creates a db/schema_cache.yml file
rake db:schema:dump # Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)
rake db:schema:load # Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the database
rake db:seed # Loads the seed data from db/seeds.rb
rake db:seed:replant # Truncates tables of each database for current environment and loads the seeds
rake db:setup # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
rake db:structure:dump # Dumps the database structure to db/structure.sql
rake db:structure:load # Recreates the databases from the structure.sql file
rake db:version # Retrieves the current schema version number
rake log:clear # Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake middleware # Prints out your Rack middleware stack
rake restart # Restart app by touching tmp/restart.txt
rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rake stats # Report code statistics (KLOCs, etc) from the application or engine
rake test # Runs all tests in test folder except system ones
rake test:all # Runs all tests, including system tests
rake test:db # Run tests quickly, but also reset db
rake test:system # Run system tests only
rake time:zones[country_or_offset] # List all time zones, list by two-letter country code (`bin/rails time:zones[US]`), or list by UTC offset (`bin/rails time:zones[-8]`)
rake tmp:clear # Clear cache, socket and screenshot files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear, tmp:screenshots:clear)
rake tmp:create # Creates tmp directories for cache, sockets, and pids
rake webpacker # Lists all available tasks in Webpacker
rake webpacker:binstubs # Installs Webpacker binstubs in this application
rake webpacker:check_binstubs # Verifies that webpack & webpack-dev-server are present
rake webpacker:check_node # Verifies if Node.js is installed
rake webpacker:check_yarn # Verifies if Yarn is installed
rake webpacker:clean[keep,age] # Remove old compiled webpacks
rake webpacker:clobber # Remove the webpack compiled output directory
rake webpacker:compile # Compile JavaScript packs using webpack for production with digests
rake webpacker:info # Provide information on Webpacker's environment
rake webpacker:install # Install Webpacker in this application
rake webpacker:install:angular # Install everything needed for Angular
rake webpacker:install:coffee # Install everything needed for Coffee
rake webpacker:install:elm # Install everything needed for Elm
rake webpacker:install:erb # Install everything needed for Erb
rake webpacker:install:react # Install everything needed for React
rake webpacker:install:stimulus # Install everything needed for Stimulus
rake webpacker:install:svelte # Install everything needed for Svelte
rake webpacker:install:typescript # Install everything needed for Typescript
rake webpacker:install:vue # Install everything needed for Vue
rake webpacker:verify_install # Verifies if Webpacker is installed
rake webpacker:yarn_install # Support for older Rails versions
rake yarn:install # Install all JavaScript dependencies as specified via Yarn
rake zeitwerk:check # Checks project structure for Zeitwerk compatibility
I just discovered that rake routes were deprecated on rails 6.1 in favor of rails routes: https://github.com/rails/rails/commit/41ad613e4c5d6c05f20ac0437564ff0d31ab9f5a
bin/rake routes is deprecated. You can Use bin/rails routes
You can try using rails routes instead of rake routes.
You can use rails routes --expanded for a very clean output even on small screens.
I'm building a Rails Engine inside another rails app. The engine's rake tasks seem to get scoped to app:
# inside <app_root>/engines/engine_name
$ rake -T apartment
rake app:apartment:migrate # Migrate all tenants
Whereas from the app's root:
#inside <app_root>/
$ rake -T apartment
rake apartment:migrate # Migrate all tenants
My problem is when I run
# inside <app_root>/engines/engine_name
RAILS_ENV=test rake db:migrate
I get the following error:
rake aborted! Don't know how to build task 'apartment:migrate'
Seems like it should be calling the app:apartment:migrate task, but I'm not sure how to do this so I can test this engine on its own with RSpec
You should have a Rakefile for the engine here: <app_root>/engines/engine_name/Rakefile
Try adding this line to the bottom of it to load the rake tasks from the apartment gem:
load 'tasks/apartment.rake'
I'm updating a rails 2.x app to rails 3.0.12.
This app used the bootstrapper gem to "seed" the database. The original fork of the gem seems to have stopped in the rails 2.x branch, but I found this other fork which is (in theory) compatible with rails 3.2 (notice that I'm updating to 3.0.12, not 3.2).
So this is what my Gemfile has now:
gem 'bootstrapper', :git => 'git://github.com/vivrass/bootstrapper.git'
After running bundle update, this seems to work ... except that the gem is supposed to add a new rake task called rake db:bootstrap, and it doesn't appear when I execute rake -T db (which I have aliased to bundle exec rake -T db via oh-my-zsh).
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:crea...
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database.
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:res...
rake db:structure:dump # Dump the database structure to an SQL file
rake db:version # Retrieves the current schema version number
I've checked the repo, and according to this post it seems that the gem is doing the right things:
- It has a railtie.rb file which loads the rake file
- The railtie.rb file is included in the lib/bootstraper.rb file
And yet, the rake task doesn't appear.
Has the process of adding rake tasks to a gem changed from rails 3.0.x to 3.2.x in any significant way?
I'm running ruby 1.9.3.
Thanks.
EDIT:
I created a new empty rails project in rails 3.0.12, added the line on the Gemfile, and after bundling, the rake task appears. This might be related with the fact that I'm updating from rails 2.x instead of creating a brand new rails 3.0.12 project.
Ok, found the problem.
The old (rails 2.x) bootstrapper gem needed a file called lib/tasks/bootstrapper.rake . I sill had that file on my rails project, and it was messing around with the rake tasks. Removing the file solved the issue.
Using Rails 2.3.5
I would like to download all the gems corresponding a new application I cloned.
I can't remember the command.
Try this to install all gems specified in environment.rb:
rake gems:install
You can always use this to see all tasks
rake -T
I am deploying my rails app to a linux server and i have some of the rake tasks missing inlcuding rake gems:install and rake db
I am running rails 2.3.4 from GEM.
Why is this?
How do I fix this? can I update somehow?
they are missing from rake -T list
rake apache2 # Build Apache 2 module
rake clean # Remove compiled files
rake clobber # Remove all generated files
rake default # Build everything
rake doc # Generate all documentation
rake doxygen # Generate Doxygen C++ API documentation if ...
rake doxygen:clobber # Remove generated Doxygen C++ API documenta...
rake doxygen:force # Force generation of Doxygen C++ API docume...
rake fakeroot # Create a fakeroot, useful for building nat...
rake nginx # Build Nginx helper server
rake package # Build all the packages
rake package:clean # Remove package products
rake package:debian # Create a Debian package
rake package:force # Force a rebuild of the package files
rake package:gem # Build the gem file passenger-2.2.4.gem
rake rdoc # Build the rdoc HTML Files
rake rdoc:clobber # Remove rdoc products
rake rdoc:force # Force a rebuild of the RDOC files
rake sloccount # Run 'sloccount' to see how much code Passe...
rake test # Run all unit tests and integration tests
rake test:cxx # Run unit tests for the Apache 2 and Nginx ...
rake test:integration # Run all integration tests
rake test:integration:apache2 # Run Apache 2 integration tests
rake test:integration:nginx # Run Nginx integration tests
rake test:oxt # Run unit tests for the OXT library
rake test:rcov # Run coverage tests for the Ruby libraries
rake test:restart # Run the 'restart' integration test infinit...
rake test:ruby # Run unit tests for the Ruby libraries
my rake file contains this:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
How do I add the gems and db rake tasks? and why are they missing?
What is the output of rake -T? This should list all avaiable tasks. In a RoR application, the Rakefile defines your tasks.
You can update gems using gem update.
Check your Capfile, if you are in fact running the gems:install from Capistrano. Apparently, the way to do this is to ensure you're in the right directory internally when running Capistrano.
namespace :gems do
desc "Install gems"
task :install, :roles => :app do
run "cd #{current_path} && #{sudo} rake RAILS_ENV=production gems:install"
end
end
You could also always specify the Rakefile to be sure using the -f [FILE] option in front of the rake command.
You could try updating your Rails install, or reinstalling rails altogether by passing the --force flag. Do you have any other projects for which this command works? Check the rake files from those projects. It looks like your rakefile is the same as mine though... Is this project originally based on an older version of rails? What Gem version are you running? You might need to do a gem update --system. All these are possibilities.
I suppose you could always recreate your project. Annoying but always seems to help worst case scenario.
At least that'll give you an idea of whether or not it's the project or something in some kind of dependencies issue.
If you are using a rails app, you also have rake tasks defined in lib/tasks/SOME_TASK.rake
if you define the SOME_TASK it will then show up when you run rake -T and be an available command.