How do I specify the postgis extension version for Rails 6? - ruby-on-rails

I've got a Rails installation (Ruby 2.7.0p0, Rails 6.0.3.7) using Postgres 15.1 (Ubuntu 15.1-1.pgdg22.04+1). In a db console, I can run:
# create extension "postgis" version "3.3.2";
In db/schema.rb, I have:
enable_extension "postgis"
But when I try to run rake db:reset, I get the error:
ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR: extension "postgis" has no installation script nor update path for version "3.2.0"
How do I tell Rails (or rake) what version (3.3.2) I want to use for postgis? enable_extension seems to take no parameters. Where does Rails even determine to use 3.2.0 in the first place?
I've also attempted to install postgis 3.2.0 in order to appease rake, but (a) that shouldn't be necessary, it seems, and (b) https://postgis.net/source/ doesn't list a "3.2.0" release.

Some statements can't be mapped cleanly to existing ActiveRecord methods, so I replaced the line enable_extension "postgis" with:
ActiveRecord::Base.connection.execute('create extension "postgis" version "3.3.2";')
... and this allowed the task to proceed.

Related

Rails migration fails for`tsvector` with `ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error`

I'm trying to run migrations on an existing Rails 7 app implementing search functionality in PostgreSQL.
Unfortunately, I'm having a problem with getting the migration to add the tsvector column.
Error when trying to run bundle exec rake db:migrate --trace:
rails aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "("
LINE 1: ...earchable_index_col" tsvector GENERATED ALWAYS AS (to_tsvect...
Link to full console output: Public gist
The full migration file:
class AddIndexForSearchableFieldsInDevelopers < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
ALTER TABLE developers
ADD COLUMN textsearchable_index_col tsvector
GENERATED ALWAYS AS (to_tsvector('simple', coalesce(hero, '') || ' ' || coalesce(bio, ''))) STORED;
SQL
add_index :developers, :textsearchable_index_col, using: :gin, name: :textsearchable_index
end
def down
remove_index :developers, name: :textsearchable_index
remove_column :developers, :textsearchable_index_col
end
end
Ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
PostgreSQL: psql (PostgreSQL) 14.3
Rails: Rails 7.0.2.4
MacBook: On MacOS Monterey MacBook Pro (13-inch, 2020) 12.3.1
Found it!
The root cause was because that syntax isn't supported by my old PostgreSQL version (installed via Homebrew).
Upgrading like so fixed all the things:
Installed PostgreSQL via Homebrew?
Check your PostgreSQL version like so:
psql [username with correct permissions]
Then, check your version like so:
select version();
Your version should be at least 13.7. Here's mine:
PostgreSQL 13.7 on x86_64-apple-darwin21.3.0, compiled by Apple clang version 13.1.6 (clang-1316.0.21.2), 64-bit
If your version is lower than 13.7, upgrade like so:
brew install postgresql#13

i am using rails 2.3.10 and i am using mysql database i try to create database for that time i am getting this error

DEPRECATION WARNING: Rake tasks in vendor/plugins/restful-authentication/tasks are deprecated. Use lib/tasks instead. (called from /home/laxmimayee/.rvm/gems/ruby-1.8.7-p374#catechumen/gems/rails-2.3.10/lib/tasks/rails.rb:10)
You need to add correct version of gem rake. I would suggest not to use rails 2. Support for rails 2 has been deprecated now. Try latest version of rails

can't generate mongoid config file with rails generate

shaunstanislaus#Master ~/workspace/mongodb_rails_project/sodibee (master) $ rails g mongoid:config
Could not find generator 'mongoid:config'. Maybe you meant 'migration' or 'controller' or 'generator'
Run `rails generate --help` for more options
Okay, I resolved it.
Firstly, my mongoid is outdated and was using 1.0.6, the latest current version is 4.0.1.
Specify in your gems mongoid, 4.0.1
It thus would require you to also include gem 'moped', '2.0.2'.
I am assuming you have bson and bson_ext too.
Then do:
spring stop
spring restart
Lastly, try:
rails g mongoid:config
You should see the new file:
create config/mongoid.yml
The older version get's installed when you don't mention a specific mongoid version and the mentioned rails version does not support the latest mongoid version. In this case, the older mongoid version get's installed.
So if this happens with anyone, check the compatibility chart published by mongoid
https://docs.mongodb.com/mongoid/current/tutorials/mongoid-installation/

Upgrade from Rails 3 to Rails 4 - Issues with activerecord-sqlserver-adapter 4.1.0 and rails 4.1.4 "Rake Tasks Not Supported"

I'm trying to run rake tasks such as db:reset and getting the error "Rake tasks not supported by 'sqlserver' adapter."
I'm running ruby 2.1.2, rails 4.1.4, rake 10.3.2, and activerecord-sqlserver-adapter 4.1.0.
I've been using the adapter with Rails 3 and running db:reset without trouble, but now I'm trying to upgrade an app to Rails 4 and running into this problem. To isolate, I created an empty new Rails 4 app, added the adapter to the Gemfile, and updated database.yml to point to my SQL Server. I get the error above when I run rake db:reset.
I've tried setting up the workaround described in https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Rails-DB-Rake-Tasks, with a minor adjustment to make it work with the latest versions of rake, but I still get the same error.
Am I doing something wrong, or is it just not possible to use tasks like db:reset with version 4 of rails and activerecord-sqlserver-adapter?
"As of 2.3.6 of the adapter, we are now compliant with the rake task interfaces in the :db namespace of rails. That means for new unix-based developers that are working with a non-legacy DB, accurately reflected by schema.rb, can now use the standard rake tasks for just about everything except actually creating the development/test databases.
The only problem is that the we have not yet committed patches upstream to rails to remove Windows specific command interpolation from their databases.rake task. So, we have to do two things to get you up and running. First, here is an extension to Rake that allows us to method chain tasks."
https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/rails-db-rake-tasks

rake aborted! ERROR: 'rake/rdoctask' is obsolete and no longer supported

I installed rails 3.2.3 in my pc but for my new project i need to work in rails 3.0.5 so I installed 3.0.5 version of rails and now when i write any rake command i get the following error
rake aborted! ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
currently this rake version is installed in my pc rake (10.1.0)
I know the error says everything but im new in ruby and rails. So i don't understand what to do. I googled it but most of the solutions ask to update rails
I know the error says everything but im new in ruby and rails. So i don't understand what to do. I googled it but most of the solutions ask to update rails
That's unfortunately the best solution. You are using a very old version of Rails that was based on some conventions of the time. Rake has changed and 10.0 is no longer compatible with that Rails version.
You should install a previous rake version. 0.9.0 should be sufficient.
In your Gemfile set
gem 'rake', '0.9.0'
then run $ bundle. Make sure you will prefix every command with
bundle exec
such as
bundle exec rake -T
instead of
rake -T
otherwise the script will fall back again using the most recent version of Rails on your machine.
For your reference, the reason of the error is probably caused by the documentation.rake file that at the very beginning it includes a deprecated rake file, removed in GH-1301.
Keep in mind that, assuming the app will then run, your first goal should be to upgrade your app. In fact, if you try to use it as it is, it's likely you will encounter so many other incompatibilities.
That was fairly simple to debug (assuming you have a reasonable knowledge of Ruby and Rails internals), but others may be harder or even impossible to fix forcing you to nothing else than upgrade.

Resources