in Education by
ActiveRecord 3.2.14 I want to use ActiveRecord in a non-Rails Ruby project. I want to have available the rake tasks that are defined by ActiveRecord. How can I do that? rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database using DATABASE_URL or 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:reset to also drop the db first) rake db:structure:dump # Dump the database structure to db/structure.sql rake db:version # Retrieves the current schema version number The above list is the list of tasks that I want to be able to use on my non-Rails Ruby project that uses ActiveRecord. What do I have to write in my Rakefile? Thanks in advance JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The easiest thing to do is to load the tasks already defined in databases.rake. Here is a GIST of how it was done. Inspired by this GIST by Drogus Rakefile.rb require 'yaml' require 'logger' require 'active_record' include ActiveRecord::Tasks class Seeder def initialize(seed_file) @seed_file = seed_file end def load_seed raise "Seed file '#{@seed_file}' does not exist" unless File.file?(@seed_file) load @seed_file end end root = File.expand_path '..', __FILE__ DatabaseTasks.env = ENV['ENV'] || 'development' DatabaseTasks.database_configuration = YAML.load(File.read(File.join(root, 'config/database.yml'))) DatabaseTasks.db_dir = File.join root, 'db' DatabaseTasks.fixtures_path = File.join root, 'test/fixtures' DatabaseTasks.migrations_paths = [File.join(root, 'db/migrate')] DatabaseTasks.seed_loader = Seeder.new File.join root, 'db/seeds.rb' DatabaseTasks.root = root task :environment do ActiveRecord::Base.configurations = DatabaseTasks.database_configuration ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym end load 'active_record/railties/databases.rake'

Related questions

0 votes
    I have a field call query_data defined as text in my MySQL database. In my model I defined this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I would like to change the user sign-in behaviour of devise in a way to redirect a user to a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Now that Rails 3 beta is out, I thought I'd have a look at rewriting an app I have just started ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    The RoR tutorials posit one model per table for the ORM to work. My DB schema has some 70 tables ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I have been trying to use routes.rb for creating a URL /similar-to-:product (where product is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    I have several properties that are dependent on the environment the application is running. For example, there ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    What is current state of the art for enabling OpenID login in Ruby on Rails applications? This is a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have been trying to use routes.rb for creating a URL /similar-to-:product (where product is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I moved a web app that was using 1.8.7 to 1.9.2 and now I keep getting incompatible character ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    A database connection defined in Repository can be reused by any Job within the project. True False...
asked Mar 25, 2021 in Technology by JackTerrance
0 votes
    In Ruby, Dir.glob("**/*.rb") (for instance) doesn't traverse symlinked directories. Is it ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the numbers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
...