From 1bd5e58c847816ae5751ee0026e55597d1541dd4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 15 Jan 2012 18:19:19 +0000 Subject: Adds support for multiple repositories per project (#779). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8650 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- db/migrate/20120115143024_add_repositories_identifier.rb | 9 +++++++++ db/migrate/20120115143100_add_repositories_is_default.rb | 9 +++++++++ db/migrate/20120115143126_set_default_repositories.rb | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 db/migrate/20120115143024_add_repositories_identifier.rb create mode 100644 db/migrate/20120115143100_add_repositories_is_default.rb create mode 100644 db/migrate/20120115143126_set_default_repositories.rb (limited to 'db') diff --git a/db/migrate/20120115143024_add_repositories_identifier.rb b/db/migrate/20120115143024_add_repositories_identifier.rb new file mode 100644 index 000000000..b54ebd1d5 --- /dev/null +++ b/db/migrate/20120115143024_add_repositories_identifier.rb @@ -0,0 +1,9 @@ +class AddRepositoriesIdentifier < ActiveRecord::Migration + def self.up + add_column :repositories, :identifier, :string + end + + def self.down + remove_column :repositories, :identifier + end +end diff --git a/db/migrate/20120115143100_add_repositories_is_default.rb b/db/migrate/20120115143100_add_repositories_is_default.rb new file mode 100644 index 000000000..87f018120 --- /dev/null +++ b/db/migrate/20120115143100_add_repositories_is_default.rb @@ -0,0 +1,9 @@ +class AddRepositoriesIsDefault < ActiveRecord::Migration + def self.up + add_column :repositories, :is_default, :boolean, :default => false + end + + def self.down + remove_column :repositories, :is_default + end +end diff --git a/db/migrate/20120115143126_set_default_repositories.rb b/db/migrate/20120115143126_set_default_repositories.rb new file mode 100644 index 000000000..cd7674e71 --- /dev/null +++ b/db/migrate/20120115143126_set_default_repositories.rb @@ -0,0 +1,14 @@ +class SetDefaultRepositories < ActiveRecord::Migration + def self.up + Repository.update_all(["is_default = ?", false]) + # Sets the last repository as default in case multiple repositories exist for the same project + Repository.connection.select_values("SELECT r.id FROM #{Repository.table_name} r" + + " WHERE r.id = (SELECT max(r1.id) FROM #{Repository.table_name} r1 WHERE r1.project_id = r.project_id)").each do |i| + Repository.update_all(["is_default = ?", true], ["id = ?", i]) + end + end + + def self.down + Repository.update_all(["is_default = ?", false]) + end +end -- cgit v1.2.3