Index: app/controllers/application_controller.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/controllers/application_controller.rb (revision b795289685e02d24a79a08eacd9d55cabc8bec9e) +++ app/controllers/application_controller.rb (revision 85e9849b69476e2f72984c77384ac73084968d99) @@ -170,7 +170,7 @@ if User.current.logged? cookies.delete(autologin_cookie_name) Token.where(["user_id = ? AND action = ?", User.current.id, 'autologin']).delete_all - Token.where(["user_id = ? AND action = ? AND value = ?", User.current.id, 'session', session[:tk]]).delete_all + Token.where(["user_id = ? AND action = ?", User.current.id, 'session']).where(:value => session[:tk]).delete_all self.logged_user = nil end end Index: app/controllers/versions_controller.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/controllers/versions_controller.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/controllers/versions_controller.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -47,13 +47,13 @@ @issues_by_version = {} if @selected_tracker_ids.any? && @versions.any? issues = Issue.visible. includes(:project, :tracker). preload(:status, :priority, :fixed_version). where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)). - order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") + order("#{Project.table_name}.lft, #{Tracker.table_name}.#{'position'.quote_column_name}, #{Issue.table_name}.id") @issues_by_version = issues.group_by(&:fixed_version) end @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} } format.api { @versions = @project.shared_versions.to_a @@ -65,10 +65,10 @@ respond_to do |format| format.html { @issues = @version.fixed_issues.visible. includes(:status, :tracker, :priority). preload(:project). - reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id"). + reorder(Issue.arel_table[:id].asc). to_a } format.api end Index: app/helpers/my_helper.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/helpers/my_helper.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/helpers/my_helper.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -37,7 +37,7 @@ limit(10). includes(:status, :project, :tracker, :priority). references(:status, :project, :tracker, :priority). - order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") + order("#{IssuePriority.table_name}.#{'position'.quote_column_name} DESC, #{Issue.table_name}.updated_on DESC") end def issuesreportedbyme_items @@ -69,7 +69,7 @@ joins(:activity, :project). references(:issue => [:tracker, :status]). includes(:issue => [:tracker, :status]). - order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). + order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.#{'position'.quote_column_name} ASC, #{Issue.table_name}.id ASC"). to_a end end Index: app/models/custom_field.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/custom_field.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) +++ app/models/custom_field.rb (revision afb29457dc1ff6f03bbc6ad2650f6abb29285286) @@ -243,7 +243,7 @@ # to move in project_custom_field def self.for_all - where(:is_for_all => true).order('position').to_a + where(:is_for_all => true).order(:position).to_a end def type_name Index: app/models/enumeration.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/enumeration.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ app/models/enumeration.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -18,7 +18,7 @@ class Enumeration < ActiveRecord::Base include Redmine::SubclassFactory - default_scope lambda {order(:position)} + default_scope lambda { order(:position) } belongs_to :project @@ -150,9 +152,9 @@ super if position_changed? self.class.where.not(:parent_id => nil).update_all( - "position = coalesce(( - select position - from (select id, position from enumerations) as parent + "#{'position'.quote_column_name} = coalesce(( + select #{'position'.quote_column_name} + from (select id, #{'position'.quote_column_name} from enumerations) as parent where parent_id = parent.id), 1)" ) end Index: app/models/issue.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2) +++ app/models/issue.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -1537,7 +1537,7 @@ if issue_id && p = Issue.find_by_id(issue_id) if p.priority_derived? # priority = highest priority of open children - if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position") + if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name.quote_table_name}.#{'position'.quote_column_name}") p.priority = IssuePriority.find_by_position(priority_position) else p.priority = IssuePriority.default Index: app/models/issue_query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue_query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/issue_query.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52) @@ -23,10 +23,10 @@ self.available_columns = [ QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id", :default_order => 'desc', :caption => '#', :frozen => true), QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true), - QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true), + QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.#{'position'.quote_column_name}", :groupable => true), QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue), - QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true), - QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true), + QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.#{'position'.quote_column_name}", :groupable => true), + QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.#{'position'.quote_column_name}", :default_order => 'desc', :groupable => true), QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"), QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true), QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), Index: app/models/issue_status.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue_status.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ app/models/issue_status.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -93,11 +96,11 @@ # First we update issues that have a journal for when the current status was set, # a subselect is used to update all issues with a single query subselect = "SELECT MAX(j.created_on) FROM #{Journal.table_name} j" + " JOIN #{JournalDetail.table_name} d ON d.journal_id = j.id" + " WHERE j.journalized_type = 'Issue' AND j.journalized_id = #{Issue.table_name}.id" + - " AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.value = :status_id" + " AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.#{'value'.quote_column_name} = :status_id" Issue.where(:status_id => id, :closed_on => nil). - update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}]) + update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}]) # Then we update issues that don't have a journal which means the # current status was set on creation Index: app/models/project.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/project.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/project.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -44,14 +44,14 @@ has_many :documents, :dependent => :destroy has_many :news, lambda {includes(:author)}, :dependent => :destroy has_many :issue_categories, lambda {order("#{IssueCategory.table_name}.name")}, :dependent => :delete_all - has_many :boards, lambda {order("position ASC")}, :dependent => :destroy + has_many :boards, lambda { order(:position) }, :dependent => :destroy has_one :repository, lambda {where(["is_default = ?", true])} has_many :repositories, :dependent => :destroy has_many :changesets, :through => :repository has_one :wiki, :dependent => :destroy # Custom field for the project issues has_and_belongs_to_many :issue_custom_fields, - lambda {order("#{CustomField.table_name}.position")}, + lambda { order(CustomField.arel_table[:position].asc) }, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' Index: app/models/query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/query.rb (revision 38bf2f2e39072da42354426272d4f58231e1d249) @@ -823,7 +823,7 @@ def sql_for_custom_field(field, operator, value, custom_field_id) db_table = CustomValue.table_name - db_field = 'value' + db_field = 'value'.quote_column_name filter = @available_filters[field] return nil unless filter if filter[:field].format.target_class && filter[:field].format.target_class <= User @@ -868,7 +868,7 @@ int_values = value.first.to_s.scan(/[+-]?\d+/).map(&:to_i).join(",") if int_values.present? if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) IN (#{int_values}))" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) IN (#{int_values}))" else sql = "#{db_table}.#{db_field} IN (#{int_values})" end @@ -877,7 +877,7 @@ end when :float if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})" else sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}" end @@ -906,7 +906,7 @@ sql = date_clause(db_table, db_field, parse_date(value.first), nil, is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) >= #{value.first.to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) >= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} >= #{value.first.to_f}" end @@ -916,7 +916,7 @@ sql = date_clause(db_table, db_field, nil, parse_date(value.first), is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) <= #{value.first.to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) <= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} <= #{value.first.to_f}" end @@ -926,7 +926,7 @@ sql = date_clause(db_table, db_field, parse_date(value[0]), parse_date(value[1]), is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})" else sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}" end @@ -1078,7 +1078,11 @@ s = [] if from if from.is_a?(Date) + if Redmine::Database.firebird? + from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day.to_date + else - from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day + from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day + end else from = from - 1 # second end @@ -1089,7 +1093,11 @@ end if to if to.is_a?(Date) + if Redmine::Database.firebird? + to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day.to_date + else - to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day + to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day + end end if self.class.default_timezone == :utc to = to.utc Index: app/models/repository.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/repository.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/repository.rb (revision 85e9849b69476e2f72984c77384ac73084968d99) @@ -420,12 +420,12 @@ # Notes: # - this hash honnors the users mapping defined for the repository def stats_by_author - commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id") + commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*) as commit_count").group("committer, user_id") #TODO: restore ordering ; this line probably never worked #commits.to_a.sort! {|x, y| x.last <=> y.last} - changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id") + changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*) as commit_count").group("committer, user_id") user_ids = changesets.map(&:user_id).compact.uniq authors_names = User.where(:id => user_ids).inject({}) do |memo, user| @@ -440,9 +440,9 @@ end hash[mapped_name] ||= { :commits_count => 0, :changes_count => 0 } if element.is_a?(Changeset) - hash[mapped_name][:commits_count] += element.count.to_i + hash[mapped_name][:commits_count] += element.commit_count.to_i else - hash[mapped_name][:changes_count] += element.count.to_i + hash[mapped_name][:changes_count] += element.commit_count.to_i end hash end Index: app/models/time_entry_query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/time_entry_query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/time_entry_query.rb (revision f1ecd5cccd87521ad1197bd7f26c321ca32cf673) @@ -25,10 +25,10 @@ QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true), QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => l(:label_week)), QueryColumn.new(:user, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), - QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true), + QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.#{'position'.quote_column_name}", :groupable => true), QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"), - QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.position"), - QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.position"), + QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.#{'position'.quote_column_name}"), + QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.#{'position'.quote_column_name}"), QueryColumn.new(:comments), QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true), ] Index: app/models/user.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/user.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ app/models/user.rb (revision 85e9849b69476e2f72984c77384ac73084968d99) @@ -683,7 +683,7 @@ # Returns true if the user is allowed to delete the user's own account def own_account_deletable? Setting.unsubscribe? && - (!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?) + (!admin? || User.active.where("id <> ?", id).where(:admin => true).exists?) end safe_attributes 'firstname', @@ -820,8 +820,9 @@ where(["property = 'attr' AND prop_key = 'assigned_to_id' AND old_value = ?", id.to_s]). update_all(['old_value = ?', substitute.id.to_s]) JournalDetail. - where(["property = 'attr' AND prop_key = 'assigned_to_id' AND value = ?", id.to_s]). - update_all(['value = ?', substitute.id.to_s]) + where(["property = 'attr' AND prop_key = 'assigned_to_id'"]). + where(:value => id.to_s). + update_all(:value => substitute.id.to_s) Message.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id]) News.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id]) # Remove private queries and keep public ones Index: db/migrate/007_create_journals.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/007_create_journals.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/007_create_journals.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -22,7 +22,7 @@ end # indexes - add_index "journals", ["journalized_id", "journalized_type"], :name => "journals_journalized_id" + add_index "journals", ["journalized_id", "journalized_type"] add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0 Index: db/migrate/072_add_enumerations_position.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/072_add_enumerations_position.rb (revision b5fede3e23b04badd3d344f8684450a1e4efccac) +++ db/migrate/072_add_enumerations_position.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94) @@ -4,7 +4,7 @@ Enumeration.all.group_by(&:opt).each do |opt, enums| enums.each_with_index do |enum, i| # do not call model callbacks - Enumeration.where({:id => enum.id}).update_all("position = #{i+1}") + Enumeration.where({:id => enum.id}).update_all(:position => (i+1)) end end end Index: db/migrate/078_add_custom_fields_position.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/078_add_custom_fields_position.rb (revision b5fede3e23b04badd3d344f8684450a1e4efccac) +++ db/migrate/078_add_custom_fields_position.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94) @@ -4,7 +4,7 @@ CustomField.all.group_by(&:type).each do |t, fields| fields.each_with_index do |field, i| # do not call model callbacks - CustomField.where({:id => field.id}).update_all("position = #{i+1}") + CustomField.where({:id => field.id}).update_all(:position => (i+1)) end end end Index: db/migrate/107_add_open_id_authentication_tables.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/107_add_open_id_authentication_tables.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/107_add_open_id_authentication_tables.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -1,12 +1,12 @@ class AddOpenIdAuthenticationTables < ActiveRecord::Migration def self.up - create_table :open_id_authentication_associations, :force => true do |t| + create_table :open_id_auth_associations, :force => true do |t| t.integer :issued, :lifetime t.string :handle, :assoc_type t.binary :server_url, :secret end - create_table :open_id_authentication_nonces, :force => true do |t| + create_table :open_id_auth_nonces, :force => true do |t| t.integer :timestamp, :null => false t.string :server_url, :null => true t.string :salt, :null => false @@ -14,7 +14,7 @@ end def self.down - drop_table :open_id_authentication_associations - drop_table :open_id_authentication_nonces + drop_table :open_id_auth_associations + drop_table :open_id_auth_nonces end end Index: db/migrate/20130201184705_add_unique_index_on_tokens_value.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -2,7 +2,7 @@ def up say_with_time "Adding unique index on tokens, this may take some time..." do # Just in case - duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1") + duplicates = Token.group(:value).having('COUNT(id) > 1').select(:value).to_a Token.where(:value => duplicates).delete_all add_index :tokens, :value, :unique => true, :name => 'tokens_value' Index: db/migrate/20130215111141_populate_issues_closed_on.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/20130215111141_populate_issues_closed_on.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ db/migrate/20130215111141_populate_issues_closed_on.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -10,7 +10,7 @@ " AND #{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id" + " AND #{JournalDetail.table_name}.property = 'attr' AND #{JournalDetail.table_name}.prop_key = 'status_id'" + " AND #{JournalDetail.table_name}.old_value NOT IN (#{closed_status_values})" + - " AND #{JournalDetail.table_name}.value IN (#{closed_status_values})" + " AND " + JournalDetail.arel_table[:value].in(closed_status_values).to_sql Issue.update_all "closed_on = (#{subselect})" # Then set closed_on for closed issues that weren't up updated by the above UPDATE Index: db/migrate/20141029181824_remove_issue_statuses_is_default.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/20141029181824_remove_issue_statuses_is_default.rb (revision b5fede3e23b04badd3d344f8684450a1e4efccac) +++ db/migrate/20141029181824_remove_issue_statuses_is_default.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94) @@ -6,7 +6,7 @@ def down add_column :issue_statuses, :is_default, :boolean, :null => false, :default => false # Restores the first status as default - default_status_id = IssueStatus.order("position").pluck(:id).first + default_status_id = IssueStatus.order(:position).pluck(:id).first IssueStatus.where(:id => default_status_id).update_all(:is_default => true) end end Index: lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -27,7 +27,7 @@ return if self.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods) cattr_accessor :customizable_options self.customizable_options = options - has_many :custom_values, lambda {includes(:custom_field).order("#{CustomField.table_name}.position")}, + has_many :custom_values, lambda { joins(:custom_field).merge(CustomField.order(:position)) }, :as => :customized, :dependent => :delete_all, :validate => false Index: lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision 02ee4bc8ea2af12e052d8ac1011554c84c4a8c76) @@ -107,13 +107,13 @@ clauses << "(#{CustomValue.table_name}.custom_field_id IN (#{fields.map(&:id).join(',')}) AND (#{visibility}))" end visibility = clauses.join(' OR ') r |= fetch_ranks_and_ids( search_scope(user, projects, options). joins(:custom_values). where(visibility). - where(search_tokens_condition(["#{CustomValue.table_name}.value"], tokens, options[:all_words])), + where(search_tokens_condition(["#{CustomValue.table_name}.#{'value'.quote_column_name}"], tokens, options[:all_words])), options[:limit] ) queries += 1 end Index: lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -1,6 +1,6 @@ module OpenIdAuthentication class Association < ActiveRecord::Base - self.table_name = :open_id_authentication_associations + self.table_name = :open_id_auth_associations def from_record OpenID::Association.new(handle, secret, issued, lifetime, assoc_type) Index: lib/redmine/acts/positioned.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/acts/positioned.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ lib/redmine/acts/positioned.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52) @@ -84,12 +84,16 @@ end end + def position_column + 'position'.quote_column_name + end + def insert_position - position_scope.where("position >= ? AND id <> ?", position, id).update_all("position = position + 1") + position_scope.where("#{position_column} >= ? AND id <> ?", position, id).update_all("#{position_column} = #{position_column} + 1") end def remove_position - position_scope_was.where("position >= ? AND id <> ?", position_was, id).update_all("position = position - 1") + position_scope_was.where("#{position_column} >= ? AND id <> ?", position_was, id).update_all("#{position_column} = #{position_column} - 1") end def position_scope_changed? @@ -99,7 +103,7 @@ def shift_positions offset = position_was <=> position min, max = [position, position_was].sort - r = position_scope.where("id <> ? AND position BETWEEN ? AND ?", id, min, max).update_all("position = position + #{offset}") + r = position_scope.where("id <> ? AND #{position_column} BETWEEN ? AND ?", id, min, max).update_all("#{position_column} = #{position_column} + #{offset}") if r != max - min reset_positions_in_list end Index: lib/redmine/core_ext/string.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/core_ext/string.rb (revision 6fc8f0c45e7e9bb7296ea0994afb3df3bcc51c68) +++ lib/redmine/core_ext/string.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) @@ -8,4 +8,12 @@ def is_binary_data? ( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty? end + + def quote_column_name + ActiveRecord::Base.connection.quote_column_name(self) + end + + def quote_table_name + ActiveRecord::Base.connection.quote_table_name(self) + end end Index: lib/redmine/database.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/database.rb (revision 61ca8f3bf9e05c882775bfb9d47801f31ba37420) +++ lib/redmine/database.rb (revision 02ee4bc8ea2af12e052d8ac1011554c84c4a8c76) @@ -49,6 +49,11 @@ (ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present? end + # Returns +true+ if the database is Firebird or RedDatabase + def firebird? + (ActiveRecord::Base.connection.adapter_name =~ /fb/i).present? + end + # Returns a SQL statement for case/accent (if possible) insensitive match def like(left, right, options={}) neg = (options[:match] == false ? 'NOT ' : '') Index: lib/redmine/field_format.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/field_format.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2) +++ lib/redmine/field_format.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52) @@ -265,7 +265,7 @@ # Returns nil if the custom field can not be used for sorting. def order_statement(custom_field) # COALESCE is here to make sure that blank and NULL values are sorted equally - "COALESCE(#{join_alias custom_field}.value, '')" + "COALESCE(#{join_alias custom_field}.#{value_column}, '')" end # Returns a GROUP BY clause that can used to group by custom value @@ -283,7 +283,7 @@ " AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" + " AND #{alias_name}.custom_field_id = #{custom_field.id}" + " AND (#{custom_field.visibility_by_project_condition})" + - " AND #{alias_name}.value <> ''" + + " AND #{alias_name}.#{value_column} <> ''" + " AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" + " WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" + " AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" + @@ -293,6 +293,10 @@ def join_alias(custom_field) "cf_#{custom_field.id}" end + + def value_column + 'value'.quote_column_name + end protected :join_alias end @@ -402,7 +406,7 @@ # Make the database cast values into numeric # Postgresql will raise an error if a value can not be casted! # CustomValue validations should ensure that it doesn't occur - "CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))" + "CAST(CASE #{join_alias custom_field}.#{value_column} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_column} END AS decimal(18,3))" end # Returns totals for the given scope @@ -410,7 +414,7 @@ scope.joins(:custom_values). where(:custom_values => {:custom_field_id => custom_field.id}). where.not(:custom_values => {:value => ''}). - sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))") + sum("CAST(#{CustomValue.table_name}.#{value_column} AS decimal(18,3))") end def cast_total_value(custom_field, value) @@ -690,7 +694,7 @@ end def group_statement(custom_field) - "COALESCE(#{join_alias custom_field}.value, '')" + "COALESCE(#{join_alias custom_field}.#{value_column}, '')" end def join_for_order_statement(custom_field) @@ -701,13 +705,13 @@ " AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" + " AND #{alias_name}.custom_field_id = #{custom_field.id}" + " AND (#{custom_field.visibility_by_project_condition})" + - " AND #{alias_name}.value <> ''" + + " AND #{alias_name}.#{value_column} <> ''" + " AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" + " WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" + " AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" + " AND #{alias_name}_2.custom_field_id = #{alias_name}.custom_field_id)" + " LEFT OUTER JOIN #{target_class.table_name} #{value_join_alias custom_field}" + - " ON CAST(CASE #{alias_name}.value WHEN '' THEN '0' ELSE #{alias_name}.value END AS decimal(30,0)) = #{value_join_alias custom_field}.id" + " ON CAST(CASE #{alias_name}.#{value_column} WHEN '' THEN '0' ELSE #{alias_name}.#{value_column} END AS decimal(18,0)) = #{value_join_alias custom_field}.id" end def value_join_alias(custom_field) Index: lib/tasks/migrate_from_mantis.rake IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/tasks/migrate_from_mantis.rake (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/tasks/migrate_from_mantis.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -52,7 +52,7 @@ TRACKER_BUG = Tracker.find_by_position(1) TRACKER_FEATURE = Tracker.find_by_position(2) - roles = Role.where(:builtin => 0).order('position ASC').all + roles = Role.where(:builtin => 0).order(:position).all manager_role = roles[0] developer_role = roles[1] DEFAULT_ROLE = roles.last Index: lib/tasks/migrate_from_trac.rake IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/tasks/migrate_from_trac.rake (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/tasks/migrate_from_trac.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -60,7 +60,7 @@ 'patch' =>TRACKER_FEATURE } - roles = Role.where(:builtin => 0).order('position ASC').all + roles = Role.where(:builtin => 0).order(:position).all manager_role = roles[0] developer_role = roles[1] DEFAULT_ROLE = roles.last Index: test/unit/query_test.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/unit/query_test.rb (revision b795289685e02d24a79a08eacd9d55cabc8bec9e) +++ test/unit/query_test.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52) @@ -161,8 +161,9 @@ query = IssueQuery.new(:project => Project.find(1), :name => '_') query.add_filter('fixed_version_id', '!*', ['']) query.add_filter('cf_1', '!*', ['']) + value_col = 'value'.quote_column_name assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL") - assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''") + assert query.statement.include?("#{CustomValue.table_name}.#{value_col} IS NULL OR #{CustomValue.table_name}.#{value_col} = ''") find_issues_with_query(query) end @@ -196,8 +197,9 @@ query = IssueQuery.new(:project => Project.find(1), :name => '_') query.add_filter('fixed_version_id', '*', ['']) query.add_filter('cf_1', '*', ['']) + value_col = 'value'.quote_column_name assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL") - assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''") + assert query.statement.include?("#{CustomValue.table_name}.#{value_col} IS NOT NULL AND #{CustomValue.table_name}.#{value_col} <> ''") find_issues_with_query(query) end Index: test/unit/user_test.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/unit/user_test.rb (revision afb29457dc1ff6f03bbc6ad2650f6abb29285286) +++ test/unit/user_test.rb (revision b5fede3e23b04badd3d344f8684450a1e4efccac) @@ -1051,7 +1051,7 @@ end def test_own_account_deletable_should_be_false_for_a_single_admin - User.where(["admin = ? AND id <> ?", true, 1]).delete_all + User.where(["id <> ?", 1]).where(:admin => true).delete_all with_settings :unsubscribe => '1' do assert_equal false, User.find(1).own_account_deletable? Index: test/object_helpers.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/object_helpers.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824) +++ test/object_helpers.rb (revision afb29457dc1ff6f03bbc6ad2650f6abb29285286) @@ -65,7 +65,7 @@ @generated_tracker_name.succ! tracker = Tracker.new(attributes) tracker.name = @generated_tracker_name.dup if tracker.name.blank? - tracker.default_status ||= IssueStatus.order('position').first || IssueStatus.generate! + tracker.default_status ||= IssueStatus.order(:position).first || IssueStatus.generate! yield tracker if block_given? tracker end