Postgresql rake db的JRuby JDBC设置:迁移任务
我有一个ruby Sinatra应用程序和Postgresql rake db的JRuby JDBC设置:迁移任务,postgresql,jdbc,sinatra,jruby,sinatra-activerecord,Postgresql,Jdbc,Sinatra,Jruby,Sinatra Activerecord,我有一个ruby Sinatra应用程序和gem pg为了使用一些Java开源应用程序,我转而使用jruby。这是jruby-srakedb:migrate的输出 NoMethodError: undefined method `get_oid_type' for #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x294f9d50> api/tasks/db.rake:18:in `block in (root)' db.rake:
gem pg
为了使用一些Java开源应用程序,我转而使用jruby。这是jruby-srakedb:migrate的输出
NoMethodError: undefined method `get_oid_type' for #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x294f9d50>
api/tasks/db.rake:18:in `block in (root)'
db.rake:#18
ActiveRecord::Migrator.migrate“#{File.dirname(File)}/./db/migrate”,ENV['VERSION']?环境['VERSION'].至_i:无
我正在用jdbc运行postgresql
更新
我将postgresql.jar添加到我的jruby路径(由brew在我的mac中安装的jruby)中,得到了相同的错误。我还删除了jar文件,并没有发现驱动程序错误
谢谢你的帮助。我找到了解决办法
首先确保您的GEM文件中包含以下内容
require 'active_record'
require 'jdbc/postgresql'
namespace :db do
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql:db_name',
:username => 'username',
:password => 'password'
)
end
desc 'Migrate the MOT core models (options: VERSION=x, VERBOSE=false)'
task :migrate => :environment do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : nil
end
desc 'Rolls the schema back to the previous version of MOT core model(specify steps w/ STEP=n).'
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
ActiveRecord::Migrator.rollback "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : step
end
end
gem 'activerecord-jdbc-adapter', :require => 'arjdbc'
gem 'activerecord-jdbcpostgresql-adapter'
然后在数据库迁移任务中,这是环境的设置:
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbcpostgresql',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql://localhost/YOUR_DATABASE_NAME'
)
end
这也是数据库。yaml
用于开发:
development:
adapter: jdbcpostgresql
driver: org.postgresql.Driver
encoding: unicode
url: jdbc:postgresql://localhost/YOUR_DATABASE_NAME
username: USER_NAME
password: PASSWORD
在Sinatra应用程序上使用Jruby享受您的JDBC 只需在您的配置中使用适配器:postgresql,它应该可以正常工作。我真的不明白是谁给了-1,因为这对我来说是100%有效的,您的呼叫-问题是您复制了数据库配置,这可能最终会咬到您。本质上,问题似乎是加载AR的任务,这些任务与MRI一起工作,而不是AR-JDBC中可用的任务。。。所以一个“好”的答案应该能解决这个问题!无论如何,我不接受这个解决方案,因为这对我不起作用。