We want to create session table in our rails (3.2.9) engine. But rake db:sessions:create does not work in rails engine root directory (only works under the dummy directory). Is there way to create sessions in rails engine? Or can we add rake db:sessions:create in Rakefile for the engine so we can use the rake command?
Thanks for the help.
As an engine is not a rails app, it's not linked with a database and you cannot create the session table, only add a migration for that.
Couldn't you just copy the migration from dummy to the migrations folder of your engine ?
Related
While I'm creating a new rails app, there is no db directory while skipping active record for using mongodb later, By this command.
rails new app-name --skip-active-record
where rails new app-name created db as expected. And so, rake db:create or rake db:migrate don't act expectedly. I need to edit /db/seeds.rb & i cann't find it.
I tried some post fixing, nothing brings the missing directory. I'm new in rails. Have I missed something? Thanks for cooperating.
By including --skip-active-record in the new command, you are telling Rails to not generate the database files, which is correct if you want to use MongoDB!
Next, you need to remove the sqlite gem from your gemfile and add the MongoDb gem to the gem file. Here is the Ruby Gems page for MongoDB, just copy the gemfile reference from there and paste it into your gemfile. You always need to run the bundle command after altering your gemfile
Then you run rails g mongoid:config and rails will generate the config/mongoid.yml for you.
Here is an article for reference: https://gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid
MongoDB does not have a schema so you don't need migrations. Thats kind of the whole point of a schema-less database.
db/seeds.rb is just a plain Ruby file thats executed when you run rake db:seed*. You can create it by running $ touch db/seeds.rb.
There is nothing magical about it.
If you are using Mongoid then everything you need is generated when you run:
$ rails g mongoid:config
So just relax.
I am deploying a heroku app.
I'm running ubuntu 14.04LTS
After git cloning, I copied the migrate files from my previous project and ran:
bin/rake db:create db:migrate
Everything seemed to be going well until I checked the models folder.
why does rake not create models? How do I fix this?
There is a typo here: it is db:migrate (instead of bd:migrate). Also, rake does not create models.
To create models along with migrations, use rails generate model MyModel.
On the other hand, if all your tables are created using migrations, then just create the model files manually in the app/models folder.
Is there any way to take a running database and generate a migration file from it? If not does anyone have any advice on how to approach that?
Background: Have a new project where a PHP developer jumped into a rails project and starting adding tables and columns though PostGres admin tool.
Created a directory called "log" then ran this command
RAILS_ENV=production rake db:schema:dump
I have a Rails app that mounts 3 engines. Each engines has their own db migrations with timestamp in the naming of the migration dating back in 2010xxxxxx-migration-name.rb. After i run bundle exec rake railties:install:migrations, all migrations are copied to my app db/migrate but the timestamp of migrations are not respected, they are all re-named to 2011xxxx-migration-name.rb. Any idea?
The migrations are automatically renamed to cause them to not conflict with the migrations in your application. They will all be grouped together in one cohesive series of migrations rather than split out through your application.
We ran into this problem today while upgrading an old rails app that uses a pre rails 3.1 engine. That engine used the old engine plugin from lazyatom.
This engines plugin brings it's own migrator class and did not copied migration files into the apps db/migrate folder.
If one now uses the rake task to install the plugin files into the app, the timestamp gets updated and rake db:migrate tries to run all old migrations again.
Easy fix:
Copy all old migrations via rsync into the db/migrate folder without using the rake task:
rsync -ruv FULL_ENGINE_PATH/db/migrate RAILS_APP_PATH/db
For all engine developers that came from pre rails 3.1 times:
We added an upgrade rake task into our engine to handle this. So our users can easily run:
rake alchemy:upgrade
I had the same issue, took way too long to figure it out:
If a previous migration's timestamp is bigger than current timestamp, new migrations will not use timestamps.
In our case, this was caused by someone who created a migration manually without using the generator
After creating a new Rails 3.1 gem plugin via:
rails plugin new core --full
I am trying to seed the database with:
rake db:seed
I am running into the following error:
rake aborted!
can't convert nil into String
Moving the seeds.rb file into the test/dummy/db directory seems to resolve the problem. Is there any way to let the db:seed task know what the current working directory is, or where to find the seeds.rb file? The ideal solution would be to keep seeds.rb within my engines db directory
I got this error when I made a mistake naming my seed file "seed.rb", not "seeds.rb". Hope, this helps.
Try creating your engine as
rails plugin new core --full --mountable
You should now be able to do rake db:migrate from your engine root. If it's not a mountable engine, since the generators would typically deploy to your app (in this case test/dummy or spec/dummy) it makes sense that the rake task would be run from the host application.
I solved this by creating a seeds.rb in my dummy/db directory. In the seeds.rb file I created, I just added:
require File.expand_path('../../../../db/seeds.rb', __FILE__)
This basically extends and runs the seeds.rb file in the engines db directory.
Please Note
I am using both --full and --mountable and rake db:seed did not work (plus various other things)
I am using rspec for my tests, so my dummy is in the spec/dummy directory of the engine
I modified my rake and rails so that I could get rspec working
useful posts I have found
rails 3.1 engines with rspec
Hope this helps