Redmine_Backlogs无法在设置页面中显示成功迁移

时间:2014-03-23 00:28:21

标签: ruby activerecord redmine

所以,我试图让redmine_backlogs与SQL服务器一起使用。 [我们使用的是SQL Server而不是SQLite,以便更好地扩展] 我不是Ruby程序员,但我真的想为我的团队使用这个插件,因为我们积极地将Redmine用于多个项目。

在阅读了一些Ruby教程之后,我设法做了一些修改并安装并正确迁移了插件[它出现]。

在Redmine的插件设置屏幕[管理中],它显示迁移未成功。 即使所有列表项都是绿色的,并且迁移似乎也有效。 有什么想法吗?

我所做的更改是以Active记录处理直接SQL查询的方式绕过可疑问题。

以下是我所做的更改 -

错误#1 -

C:\Projects\Redmine\redmine-2.3.2>rake redmine:plugins:migrate
Migrating redmine_backlogs (Redmine Backlogs)...
==  AddStoryPositions: migrating ==============================================
-- execute("select max(position) from issues")
   -> 0.0020s
   -> -1 rows
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `each' for -1:FixnumC:/Projects/Redmine/redmine-2.3.2/plugins/redmine_backlogs/db/migrate/026_add_story_positions.rb:10:in `up'

FIX#1 -

直接查询无法正常使用sqladapter [TinyTds + Active Record] 026_add_story_positions.rb

class AddStoryPositions < ActiveRecord::Migration
  def self.up
    # Rails doesn't support temp tables, mysql doesn't support update
    # from same-table subselect

    unless RbStory.trackers.size == 0
      max = 0
          dbconfig = YAML.load_file(File.join(File.dirname(__FILE__), '../../../../config/database.yml'))#[Rails.env]['username']

        if dbconfig[Rails.env]['adapter'] == 'sqlserver' then
            database = dbconfig[Rails.env]['database']
            dataserver = dbconfig[Rails.env]['dataserver']
            mode = dbconfig[Rails.env]['mode']
            port = dbconfig[Rails.env]['port']
            username = dbconfig[Rails.env]['username']
            password = dbconfig[Rails.env]['password']

            client = TinyTds::Client.new(
                :database => database,
                :dataserver => dataserver,
                :mode => mode,
                :port => port,
                :username => username,
                :password => password)

            client.execute("select max(position) from issues").each{|row| max = row[0]}

            client.execute "update issues
               set position = #{max} + id
               where position is null and tracker_id in (#{RbStory.trackers(:type=>:string)})"
        else
            execute("select max(position) from issues").each{|row| max = row[0]}

            execute "update issues
               set position = #{max} + id
               where position is null and tracker_id in (#{RbStory.trackers(:type=>:string)})"
        end

    end
  end

  def self.down
    puts "Reverting irreversible migration"
  end
end

错误#2 耙子流产了! 发生错误,此操作和所有后​​续迁移都已取消:

TinyTds ::错误:ALTER TABLE ALTER COLUMN位置失败,因为一个或多个对象访问此列:ALTER TABLE [issues] ALTER COLUMN [position] 整数NOT NULLC:/Projects/Redmine/redmine-2.3.2/plugins/redmine_backlogs/db/migrate/033_unique_positions.rb:30:在'up&#39;

FIX#2

033_unique_positions.rb

    #SQLServer cannot change the type of an indexes column, so it must be dropped first
   remove_index :issues, :position
    change_column :issues, :position, :integer, :null => false
    add_index :issues, :position

错误#3 耙子流产了! 未定义的方法each' for -1:Fixnum C:/Projects/Redmine/redmine-2.3.2/plugins/redmine_backlogs/lib/backlogs_setup.rb:155:in已迁移?&#39;

FIX#3

def migrated?
    available = Dir[File.join(File.dirname(__FILE__), '../db/migrate/*.rb')].collect{|m| Integer(File.basename(m).split('_')[0].gsub(/^0+/, ''))}.sort
    return true if available.size == 0
    available = available[-1]

    ran = []
    dbconfig = YAML.load_file(File.join(File.dirname(__FILE__), '../../../config/database.yml'))#[Rails.env]['username']

    if dbconfig[Rails.env]['adapter'] == 'sqlserver' then
      database = dbconfig[Rails.env]['database']
      dataserver = dbconfig[Rails.env]['dataserver']
      mode = dbconfig[Rails.env]['mode']
      port = dbconfig[Rails.env]['port']
      username = dbconfig[Rails.env]['username']
      password = dbconfig[Rails.env]['password']

      client = TinyTds::Client.new(
        :database => database,
        :dataserver => dataserver,
        :mode => mode,
        :port => port,
        :username => username,
        :password => password)

      client.execute("select version from schema_migrations where version like '%-redmine_backlogs'").each{|m|
        ran << Integer((m.is_a?(Hash) ? m.values : m)[0].split('-')[0])
      }
    else
      Setting.connection.execute("select version from schema_migrations where version like '%-redmine_backlogs'").each{|m|
        ran << Integer((m.is_a?(Hash) ? m.values : m)[0].split('-')[0])
      }
    end

    return false if ran.size == 0
    ran = ran.sort[-1]

    return ran >= available
  end
  module_function :migrated?    

我使用了错误的where子句 - 这是正确的,我必须在调试时覆盖。 &#39;% - redmine_backlogs&#39;

以上代码有效。

1 个答案:

答案 0 :(得分:0)

我之前无法回答我自己的问题,但现在我可以。 上面的代码经过测试和运行。从那以后,我一直在Windows上运行带有MS SQL的积压工作。