diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-10-31 13:00:53 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-12-08 11:47:16 +0200 |
commit | 83232be0e14cc8b35bf74532203a6e4371c15e70 (patch) | |
tree | d6cde69809c44055496954efe57b866404b3d0f2 /db/migrate | |
parent | 34fc5b050a4e70bf491be9a49cfa2dc0a7a9a9a2 (diff) | |
download | gitlab-ce-83232be0e14cc8b35bf74532203a6e4371c15e70.tar.gz |
Add nested groups support on data leveldz-nested-groups
* add parent_id field to namespaces table to store relation with nested groups
* create routes table to keep information about full path of every group and project
* project/group lookup by full path from routes table
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20161124111390_add_parent_id_to_namespace.rb | 12 | ||||
-rw-r--r-- | db/migrate/20161124111395_add_index_to_parent_id.rb | 14 | ||||
-rw-r--r-- | db/migrate/20161124111402_add_routes_table.rb | 18 | ||||
-rw-r--r-- | db/migrate/20161130095245_fill_routes_table.rb | 21 | ||||
-rw-r--r-- | db/migrate/20161130101252_fill_projects_routes_table.rb | 22 | ||||
-rw-r--r-- | db/migrate/20161202152031_remove_duplicates_from_routes.rb | 28 | ||||
-rw-r--r-- | db/migrate/20161202152035_add_index_to_routes.rb | 16 |
7 files changed, 131 insertions, 0 deletions
diff --git a/db/migrate/20161124111390_add_parent_id_to_namespace.rb b/db/migrate/20161124111390_add_parent_id_to_namespace.rb new file mode 100644 index 00000000000..a6fa1b70a9d --- /dev/null +++ b/db/migrate/20161124111390_add_parent_id_to_namespace.rb @@ -0,0 +1,12 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddParentIdToNamespace < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column(:namespaces, :parent_id, :integer) + end +end diff --git a/db/migrate/20161124111395_add_index_to_parent_id.rb b/db/migrate/20161124111395_add_index_to_parent_id.rb new file mode 100644 index 00000000000..eab74c01dfd --- /dev/null +++ b/db/migrate/20161124111395_add_index_to_parent_id.rb @@ -0,0 +1,14 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddIndexToParentId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_concurrent_index(:namespaces, [:parent_id, :id], unique: true) + end +end diff --git a/db/migrate/20161124111402_add_routes_table.rb b/db/migrate/20161124111402_add_routes_table.rb new file mode 100644 index 00000000000..a02e046a18e --- /dev/null +++ b/db/migrate/20161124111402_add_routes_table.rb @@ -0,0 +1,18 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddRoutesTable < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :routes do |t| + t.integer :source_id, null: false + t.string :source_type, null: false + t.string :path, null: false + + t.timestamps + end + end +end diff --git a/db/migrate/20161130095245_fill_routes_table.rb b/db/migrate/20161130095245_fill_routes_table.rb new file mode 100644 index 00000000000..6754e583000 --- /dev/null +++ b/db/migrate/20161130095245_fill_routes_table.rb @@ -0,0 +1,21 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class FillRoutesTable < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + DOWNTIME_REASON = 'No new namespaces should be created during data copy' + + def up + execute <<-EOF + INSERT INTO routes + (source_id, source_type, path) + (SELECT id, 'Namespace', path FROM namespaces) + EOF + end + + def down + Route.delete_all(source_type: 'Namespace') + end +end diff --git a/db/migrate/20161130101252_fill_projects_routes_table.rb b/db/migrate/20161130101252_fill_projects_routes_table.rb new file mode 100644 index 00000000000..14700583be5 --- /dev/null +++ b/db/migrate/20161130101252_fill_projects_routes_table.rb @@ -0,0 +1,22 @@ +# 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 + DOWNTIME_REASON = 'No new projects should be created during data copy' + + def up + 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 + + def down + Route.delete_all(source_type: 'Project') + end +end diff --git a/db/migrate/20161202152031_remove_duplicates_from_routes.rb b/db/migrate/20161202152031_remove_duplicates_from_routes.rb new file mode 100644 index 00000000000..510796e05f2 --- /dev/null +++ b/db/migrate/20161202152031_remove_duplicates_from_routes.rb @@ -0,0 +1,28 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveDuplicatesFromRoutes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + select_all("SELECT path FROM #{quote_table_name(:routes)} GROUP BY path HAVING COUNT(*) > 1").each do |row| + path = connection.quote(row['path']) + execute(%Q{ + DELETE FROM #{quote_table_name(:routes)} + WHERE path = #{path} + AND id != ( + SELECT id FROM ( + SELECT max(id) AS id + FROM #{quote_table_name(:routes)} + WHERE path = #{path} + ) max_ids + ) + }) + end + end + + def down + end +end diff --git a/db/migrate/20161202152035_add_index_to_routes.rb b/db/migrate/20161202152035_add_index_to_routes.rb new file mode 100644 index 00000000000..4a51337bda6 --- /dev/null +++ b/db/migrate/20161202152035_add_index_to_routes.rb @@ -0,0 +1,16 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddIndexToRoutes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_concurrent_index(:routes, :path, unique: true) + add_concurrent_index(:routes, [:source_type, :source_id], unique: true) + end +end |