How to migrate pending migrations in rails? - ruby-on-rails-4

Im working on ruby on rails open source projects. So after cloning from github i setup the mentiones pg database in Gemfile by using command rails db:create successfully it created the database . Now there are 809 migration files , to migrate with postgres database i ran the
rake db:migrate
Im getting the below error
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class CreateEvents < ActiveRecord::Migration[4.2]
D:/Freelance/pupilfirst/db/migrate/20131204110627_create_events.rb:1:in `<top (required)>'
Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class CreateEvents < ActiveRecord::Migration[4.2]
D:/Freelance/pupilfirst/db/migrate/20131204110627_create_events.rb:1:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
there are 809 migrations files are there . so can anyone help me out from this. my rails version is ``rails 6.1.5.1`

Related

Heroku + Apartment PG::Error: ERROR: function pg_stat_statements_reset() does not exist

I use Apartment gem in Rails 4 to support multi-tenancy in Postgres 9.3.3 on Heroku.
An error is occurred when Apartment gem creates a new tenant.
Deep investigation showed that a schema was created, but no tables inside.
Heroku logs showed an error:
PG::Error: ERROR: function pg_stat_statements_reset() does not exist
When a new schema is created Postgres is trying to reset stats by executing the function pg_stat_statements_reset()
By default, this function can only be executed by superusers (from original doc).
Heroku doesn't give you superuser privileges.
So you need to disable extension pg_stat_statements.
Solution 1 - Quick hot fix directly in DB
Access the Rails Console for your Heroku app:
heroku run rails c
Execute SQL statement in schema public:
ActiveRecord::Base.connection.execute("DROP EXTENSION pg_stat_statements;")
Solution 2 - via migration
Check the file db/schema.rb. Most probably it contains a line
enable_extension "pg_stat_statements"
Create a migration file
rails g migration DropExtensionPgStatStatements
define self.up method
def self.up
disable_extension "pg_stat_statements"
end
apply the migration
rake db:migrate
Now the file db/schema.rb should not contain that line
Commit changes (schema and migration files) and deploy to Heroku
rake deploy:production:migrations
Regarding the rake task see deploy.rake

How do I remove missing migrations from project?

So I have made the foolish error of manually removing migration files from my project.
They still show up in db:migrate:status, but I'm not able to rollback or destroy them without creating new empty files with MigrationID_somename, and then running destroy on those placeholder files.
Is there a better way to forget missing migration files?
me$ rake db:migrate:status
database: [...]/db/development.sqlite3
Status Migration ID Migration Name
--------------------------------------------------
up 20141203044050 ********** NO FILE **********
up 20141203044501 ********** NO FILE **********
me$ rake db:migrate:down VERSION=20141203044501
rake aborted!
ActiveRecord::UnknownMigrationVersionError:
No migration with version number 20141203044501
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.6/lib/active_record/migration.rb:932:in `run'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.6/lib/active_record/migration.rb:818:in `run'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:79:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:down
(See full trace by running task with --trace)
You could probably just use a database client and delete the rows from the schema_migrations table (if you promise never to do it again ;).

Is rails 4 supporting active_scaffold?

rails 4 + ruby 2.0
Is rails 4 is supporting active_scaffold ?
by source : https://github.com/activescaffold/active_scaffold
Overview
"ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. Rails 3.2 and 4 are supported."
When i am trying with a brand new rails project.
1) gem 'active_scaffold'
2) bundle install
3) bundle exec rake db:create
Error
This version of ActiveScaffold requires Rails 3.1 or higher. Please use an earlier version.
/home/xyz/.rvm/gems/ruby-2.0.0-p247#rails4/gems/active_scaffold-3.2.20/xyz/active_scaffold.rb:2:in <top (required)>'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:inrequire'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in block (2 levels) in require'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:ineach'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in block in require'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:ineach'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in require'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:132:inrequire'
/home/xyz/RoRProjects/active_scaff/config/application.rb:7:in <top (required)>'
/home/xyz/RoRProjects/active_scaff/Rakefile:4:inrequire'
/home/xyz/RoRProjects/active_scaff/Rakefile:4:in <top (required)>'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#rails4/bin/ruby_noexec_wrapper:14:ineval'
/home/xyz/.rvm/gems/ruby-2.0.0-p247#rails4/bin/ruby_noexec_wrapper:14:in `'
Any suggestion ?
Answer is Yes! rails 4 is supporting active_scaffold.
1) gem 'active_scaffold', github: 'activescaffold/active_scaffold'
2) bundle install
3) bundle exec rake db:create
4) rails g active_scaffold User name:string
5) bundle exec rake db:migrate
Done!

"uninitialized constant User" when setting up spree and refinery together

I have been trying to set up spree and refinery together with the following purpose :
using same authentification system for both.
According a github project and a subsequent pull into spree master branch... this should go smoothly (links available in comment of first answer)
I gave a hard try but I can't get rid of "uninitialized constant User" error. I will try to describe all the necessary steps to be able to replicate the error.
Firstofall, the environnement :
gem install rails
rails new spreefinery
cd spreefinery
# resolve a dependency on which bundler fails
sed "s/'jquery-rails'/'jquery-rails', '~>2.0.0'/g" -i Gemfile
echo "# adding custom gems for both spree and refinery
gem 'spree', :git => 'git://github.com/spree/spree.git', :branch => '1-2-stable'
gem 'spree_usa_epay'
gem 'spree_skrill'
gem 'refinerycms', :git => 'git://github.com/refinery/refinerycms.git', :branch => '2-0-stable'" >> Gemfile
bundle install
Secondly, install refinery as indicated in the guide
rails generate refinery:cms --fresh-installation
with a patch for pagination
echo "#Refinery uses the will_paginate gem for pagination,
# while Spree uses Kaminari.... This fix makes both happy
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
alias_method :per, :per_page
alias_method :num_pages, :total_pages
end
end
end
end" > config/initializers/spreefinery.rb
Eventually, install spree (without authentification)
bundle exec spree install --git=git://github.com/spree/spree.git --branch=1-2-stable
# use default config except for authentification :
Would you like to install the default gateways? (yes/no) [yes]
Would you like to install the default authentication system? (yes/no) [yes] no
What is the name of the class representing users within your application? [User]
Would you like to run the migrations? (yes/no) [yes]
Would you like to load the seed data? (yes/no) [yes]
Would you like to load the sample data? (yes/no) [yes]
This last command runs as :
gemfile spree
gemfile spree_usa_epay
gemfile spree_skrill
run bundle install from "."
create config/initializers/spree.rb
create config/spree.yml
remove public/index.html
append public/robots.txt
create app/assets/javascripts/store
create app/assets/javascripts/admin
create app/assets/stylesheets/store
create app/assets/stylesheets/admin
create app/assets/images/store
create app/assets/images/admin
create app/assets/javascripts/store/all.js
create app/assets/javascripts/admin/all.js
create app/assets/stylesheets/store/all.css
create app/assets/stylesheets/admin/all.css
create app/overrides
append config/environment.rb
append db/seeds.rb
copying migrations
creating database
running migrations
loading seed data
rake db:seed
rake aborted!
uninitialized constant User
Tasks: TOP => db:abort_if_pending_migrations => environment
(See full trace by running task with --trace)
loading sample data
insert config/routes.rb
**************************************************
We added the following line to your application's config/routes.rb file:
mount Spree::Core::Engine, :at => '/'
**************************************************
Spree has been installed successfully. You're all ready to go!
Enjoy!
You can see the error on db:seed step.
The same error comes again on rails server or rake db:migrate. Here is the full traceback:
rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant User
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/core/lib/spree/core.rb:52:in `user_class'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/app/models/spree/promotion/rules/user.rb:7:in `<class:User>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/app/models/spree/promotion/rules/user.rb:4:in `<module:Rules>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/app/models/spree/promotion/rules/user.rb:3:in `<class:Promotion>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/app/models/spree/promotion/rules/user.rb:2:in `<module:Spree>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/app/models/spree/promotion/rules/user.rb:1:in `<top (required)>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bundler/gems/spree-dbb0c56a60a9/promo/lib/spree/promo/engine.rb:44:in `block in <class:Engine>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/emb/Documents/envs/spreefinery/config/environment.rb:5:in `<top (required)>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/application.rb:103:in `require_environment!'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/gems/railties-3.2.8/lib/rails/application.rb:295:in `block (2 levels) in initialize_tasks'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/emb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/emb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bin/ruby_noexec_wrapper:14:in `eval'
/Users/emb/.rvm/gems/ruby-1.9.3-p194#spreefinery/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate => environment
I would need some help at this point. I have found some posts about this error stating than the model User might not exist... but refinery definitively declares a User class... so I am a bit confused.
Thanks for your help !
Manu
Finally got it and it looks like so easy.... mmmfff
So I just had to specify the "Refinery::User" (not simply "User") to the question about the user.
Would you like to install the default gateways? (yes/no) [yes]
Would you like to install the default authentication system? (yes/no) [yes] no
What is the name of the class representing users ...? [User] **Refinery::User**
Would you like to run the migrations? (yes/no) [yes]
Would you like to load the seed data? (yes/no) [yes]
Would you like to load the sample data? (yes/no) [yes]
So logical :)
You are trying to install spree and run the standard migrations but I can see from your entry that you have explicitly stated NOT to install the default auth system that comes with spree (which like refinery is based on devise). Therefore some of the migrations that run on the user model are failing.
> bundle exec spree install --git=git://github.com/spree/spree.git
> --branch=1-2-stable
>
> use default config except for authentification : Would you like to install the default gateways? (yes/no) [yes] Would you like to
> install the default authentication system? (yes/no) [yes] no What is
> the name of the class representing users within your application?
> [User] Would you like to run the migrations? (yes/no) [yes]
> Would you like to load the seed data? (yes/no) [yes] Would you like
> to load the sample data? (yes/no) [yes]
If you try install it again but this time say YES to "Would you like to install the default authentication system?" then it should work. I have been working on a similar system this week and its working fine. You will get two namespaced user db tables in your db, but if you want both systems sharing a single auth system then I think you are in for some work and the standard installer wont be applicable.

Spree Extension Scaffold

I have created a a spree application and used one existing extension spree_news by cloning it to my spree application folder, now when i try to create a scaffold or a resource inside the spree_news extension by trying:
wapnil#swapnil-pc:~/ecommerce/spree_news$ rails generate scaffold oerp
Pname:string Pdesc:text Pprice:float
the following error is encountered:
/home/swapnil/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- rails/engine/commands (LoadError)
from /home/swapnil/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from script/rails:8:in `<main>'
Please Help!!
The script/rails file in your extension is wrong and should be this. This is due to a bug in Spree that will be fixed in the next release.