2016-10-31 07:00:53 -04:00
|
|
|
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
|
|
|
# for more information on how to write migrations for GitLab.
|
|
|
|
|
|
|
|
class FillProjectsRoutesTable < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = true
|
2017-02-21 18:32:18 -05:00
|
|
|
DOWNTIME_REASON = 'No new projects should be created during data copy'.freeze
|
2016-10-31 07:00:53 -04:00
|
|
|
|
|
|
|
def up
|
2016-12-15 08:42:49 -05:00
|
|
|
if Gitlab::Database.postgresql?
|
|
|
|
execute <<-EOF
|
|
|
|
INSERT INTO routes (source_id, source_type, path)
|
|
|
|
(SELECT DISTINCT ON (namespaces.path, projects.path) projects.id, 'Project', concat(namespaces.path, '/', projects.path)
|
|
|
|
FROM projects INNER JOIN namespaces ON projects.namespace_id = namespaces.id
|
|
|
|
ORDER BY namespaces.path, projects.path, projects.id DESC)
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
execute <<-EOF
|
|
|
|
INSERT INTO routes (source_id, source_type, path)
|
|
|
|
(SELECT projects.id, 'Project', concat(namespaces.path, '/', projects.path)
|
|
|
|
FROM projects INNER JOIN namespaces ON projects.namespace_id = namespaces.id)
|
|
|
|
EOF
|
|
|
|
end
|
2016-10-31 07:00:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2016-12-15 08:32:06 -05:00
|
|
|
execute("DELETE FROM routes WHERE source_type = 'Project'")
|
2016-10-31 07:00:53 -04:00
|
|
|
end
|
|
|
|
end
|