Ruby on rails rake db:schema:dump生成一个空模式

Ruby on rails rake db:schema:dump生成一个空模式,ruby-on-rails,rake,Ruby On Rails,Rake,我有一个项目,目前使用RubyonRails环境的旧版本,并使用PostgreSQL数据库。这些版本是(是的,我知道……别笑,我现在必须支持这个遗留版本): 如果重要的话,这些都安装在Ubuntu 16.04系统上。这一切都是在我拥有的一个旧系统上进行的,这个系统最终死了。因此,我在新机器上设置了rvm和这些开发工具版本,并复制了数据库 在这台新机器上,除了我尝试过的几个rake数据库任务外,一切似乎都很正常。例如,如果我运行rake db:schema:dump,我不会得到任何错误输出,我会得

我有一个项目,目前使用RubyonRails环境的旧版本,并使用PostgreSQL数据库。这些版本是(是的,我知道……别笑,我现在必须支持这个遗留版本):

如果重要的话,这些都安装在Ubuntu 16.04系统上。这一切都是在我拥有的一个旧系统上进行的,这个系统最终死了。因此,我在新机器上设置了
rvm
和这些开发工具版本,并复制了数据库

在这台新机器上,除了我尝试过的几个rake数据库任务外,一切似乎都很正常。例如,如果我运行rake db:schema:dump,我不会得到任何错误输出,我会得到一个包含以下内容的
db/schema.rb
文件:

# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do

end
我尝试运行
rake db:structure:dump
,但出现错误:

/usr/lib/postgresql/9.5/bin/pg_dump: invalid option -- 'i'
Try "pg_dump --help" for more information.
rake aborted!
Error dumping database
/home/mark/.rvm/gems/ruby-1.8.7-p374@caplus/gems/rails-2.3.11/lib/tasks/databases.rake:287
/home/mark/.rvm/gems/ruby-1.8.7-p374@caplus/bin/ruby_executable_hooks:15
Tasks: TOP => db:structure:dump
(See full trace by running task with --trace)
我主要关心的是缺乏转储模式的能力。我不明白它如何运行而不出错,但不会生成模式。正如我最初提到的,该应用程序通过
script/server
运行良好。我还从控制台运行了
ActiveRecord::SchemaDumper.dump
,得到了完全相同的结果(我想这是意料之中的,因为rake任务可能就是这样运行的)。但在控制台上,我可以很好地检查任何模型和数据。都在那里


关于模式文件为什么是空的,有什么想法吗?我希望有人以前见过这种现象。我已经对rake db:schema:dump的故障模式进行了大量搜索,但在任何地方都找不到提到的特定症状。

我认为是postgresql 9.5导致了这个问题。请将postgresql降级

此行为已在rails github页面中报告 :

我希望这对你有帮助


Cheers

我做了一些挖掘,确定
PostgresqlAdapter
tables
方法返回一个空列表,即使它与数据库有有效连接。适配器源代码如下:

gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb
方法如下所示:

  # Returns the list of all tables in the schema search path or a specified schema.
  def tables(name = nil)
    schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
    query(<<-SQL, name).map { |row| row[0] }
      SELECT tablename
        FROM pg_tables
       WHERE schemaname IN (#{schemas})
    SQL
  end

我怀疑有更好的方法来解决这个问题,但这对我来说是可靠的。更不用说在这一点上,我正在使用的版本是如此古老,也许没有人关心。我确实研究了
表的后续实现,它们有点不同。

这可能解释了无效选项
I
,但我不确定它是否解释了空模式,这是一个更大的问题。我有一个朋友和我一起做同一个项目,他正在运行Postgresql 9.1.20。
  # Returns the list of all tables in the schema search path or a specified schema.
  def tables(name = nil)
    schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
    query(<<-SQL, name).map { |row| row[0] }
      SELECT tablename
        FROM pg_tables
       WHERE schemaname IN (#{schemas})
    SQL
  end
    schemas = schema_search_path.split(/,/).map { |p| quote(p.strip) }.join(',')