From be9aa7f19474424991923f128053e2523fa166d8 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 26 Jul 2016 09:35:47 +0200 Subject: Add an URL field to Environments This MR adds a string (thus max 255 chars) field to the enviroments table to expose it later in other features. --- db/migrate/20160725083350_add_external_url_to_enviroments.rb | 12 ++++++++++++ db/schema.rb | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160725083350_add_external_url_to_enviroments.rb (limited to 'db') diff --git a/db/migrate/20160725083350_add_external_url_to_enviroments.rb b/db/migrate/20160725083350_add_external_url_to_enviroments.rb new file mode 100644 index 00000000000..e887341159b --- /dev/null +++ b/db/migrate/20160725083350_add_external_url_to_enviroments.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 AddExternalUrlToEnviroments < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column(:environments, :external_url, :string) + end +end diff --git a/db/schema.rb b/db/schema.rb index 2d2ae5fd840..4365af98962 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -427,9 +427,10 @@ ActiveRecord::Schema.define(version: 20160722221922) do create_table "environments", force: :cascade do |t| t.integer "project_id" - t.string "name", null: false + t.string "name", null: false t.datetime "created_at" t.datetime "updated_at" + t.string "external_url" end add_index "environments", ["project_id", "name"], name: "index_environments_on_project_id_and_name", using: :btree -- cgit v1.2.1 From 76e9b68439510af5c783a81b93944f1c8d96d150 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 26 Jul 2016 14:19:37 +0200 Subject: Incorporate feedback --- db/migrate/20160725083350_add_external_url_to_enviroments.rb | 3 --- db/schema.rb | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'db') diff --git a/db/migrate/20160725083350_add_external_url_to_enviroments.rb b/db/migrate/20160725083350_add_external_url_to_enviroments.rb index e887341159b..21a8abd310b 100644 --- a/db/migrate/20160725083350_add_external_url_to_enviroments.rb +++ b/db/migrate/20160725083350_add_external_url_to_enviroments.rb @@ -1,6 +1,3 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - class AddExternalUrlToEnviroments < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers diff --git a/db/schema.rb b/db/schema.rb index 4365af98962..5b35a528e71 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160722221922) do +ActiveRecord::Schema.define(version: 20160726093600) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.1 From 020ea32e767b9ad033f9fedcaa902865a01fa944 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 2 Aug 2016 18:06:31 +0800 Subject: Implement pipeline hooks, extracted from !5525 Closes #20115 --- .../20160728081025_add_pipeline_events_to_web_hooks.rb | 16 ++++++++++++++++ .../20160728103734_add_pipeline_events_to_services.rb | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 db/migrate/20160728081025_add_pipeline_events_to_web_hooks.rb create mode 100644 db/migrate/20160728103734_add_pipeline_events_to_services.rb (limited to 'db') diff --git a/db/migrate/20160728081025_add_pipeline_events_to_web_hooks.rb b/db/migrate/20160728081025_add_pipeline_events_to_web_hooks.rb new file mode 100644 index 00000000000..b800e6d7283 --- /dev/null +++ b/db/migrate/20160728081025_add_pipeline_events_to_web_hooks.rb @@ -0,0 +1,16 @@ +class AddPipelineEventsToWebHooks < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column_with_default(:web_hooks, :pipeline_events, :boolean, + default: false, allow_null: false) + end + + def down + remove_column(:web_hooks, :pipeline_events) + end +end diff --git a/db/migrate/20160728103734_add_pipeline_events_to_services.rb b/db/migrate/20160728103734_add_pipeline_events_to_services.rb new file mode 100644 index 00000000000..bcd24fe1566 --- /dev/null +++ b/db/migrate/20160728103734_add_pipeline_events_to_services.rb @@ -0,0 +1,16 @@ +class AddPipelineEventsToServices < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column_with_default(:services, :pipeline_events, :boolean, + default: false, allow_null: false) + end + + def down + remove_column(:services, :pipeline_events) + end +end -- cgit v1.2.1 From 54f6266fadcadb6e423a3275858a0b0e8189b900 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 3 Aug 2016 17:26:36 +0200 Subject: Improve CI fixtures --- db/fixtures/development/14_builds.rb | 45 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'db') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 124704cb451..e65abe4ef77 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,6 +1,6 @@ class Gitlab::Seeder::Builds STAGES = %w[build notify_build test notify_test deploy notify_deploy] - + def initialize(project) @project = project end @@ -8,26 +8,26 @@ class Gitlab::Seeder::Builds def seed! pipelines.each do |pipeline| begin - build_create!(pipeline, name: 'build:linux', stage: 'build') - build_create!(pipeline, name: 'build:osx', stage: 'build') + build_create!(pipeline, name: 'build:linux', stage: 'build', status_event: :success) + build_create!(pipeline, name: 'build:osx', stage: 'build', status_event: :success) - build_create!(pipeline, name: 'slack post build', stage: 'notify_build') + build_create!(pipeline, name: 'slack post build', stage: 'notify_build', status_event: :success) - build_create!(pipeline, name: 'rspec:linux', stage: 'test') - build_create!(pipeline, name: 'rspec:windows', stage: 'test') - build_create!(pipeline, name: 'rspec:windows', stage: 'test') - build_create!(pipeline, name: 'rspec:osx', stage: 'test') - build_create!(pipeline, name: 'spinach:linux', stage: 'test') - build_create!(pipeline, name: 'spinach:osx', stage: 'test') - build_create!(pipeline, name: 'cucumber:linux', stage: 'test') - build_create!(pipeline, name: 'cucumber:osx', stage: 'test') + build_create!(pipeline, name: 'rspec:linux', stage: 'test', status_event: :success) + build_create!(pipeline, name: 'rspec:windows', stage: 'test', status_event: :success) + build_create!(pipeline, name: 'rspec:windows', stage: 'test', status_event: :success) + build_create!(pipeline, name: 'rspec:osx', stage: 'test', status_event: :success) + build_create!(pipeline, name: 'spinach:linux', stage: 'test', status: :pending) + build_create!(pipeline, name: 'spinach:osx', stage: 'test', status_event: :cancel) + build_create!(pipeline, name: 'cucumber:linux', stage: 'test', status_event: :run) + build_create!(pipeline, name: 'cucumber:osx', stage: 'test', status_event: :drop) - build_create!(pipeline, name: 'slack post test', stage: 'notify_test') + build_create!(pipeline, name: 'slack post test', stage: 'notify_test', status_event: :success) - build_create!(pipeline, name: 'staging', stage: 'deploy', environment: 'staging') - build_create!(pipeline, name: 'production', stage: 'deploy', environment: 'production', when: 'manual') + build_create!(pipeline, name: 'staging', stage: 'deploy', environment: 'staging', status_event: :success) + build_create!(pipeline, name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :success) - commit_status_create!(pipeline, name: 'jenkins') + commit_status_create!(pipeline, name: 'jenkins', status: :success) print '.' rescue ActiveRecord::RecordInvalid @@ -48,7 +48,7 @@ class Gitlab::Seeder::Builds def build_create!(pipeline, opts = {}) attributes = build_attributes_for(pipeline, opts) - build = Ci::Build.new(attributes) + build = Ci::Build.create!(attributes) if opts[:name].start_with?('build') artifacts_cache_file(artifacts_archive_path) do |file| @@ -60,23 +60,20 @@ class Gitlab::Seeder::Builds end end - build.save! - build.update(status: build_status) - if %w(running success failed).include?(build.status) # We need to set build trace after saving a build (id required) build.trace = FFaker::Lorem.paragraphs(6).join("\n\n") end end - + def commit_status_create!(pipeline, opts = {}) attributes = commit_status_attributes_for(pipeline, opts) - GenericCommitStatus.create(attributes) + GenericCommitStatus.create!(attributes) end - + def commit_status_attributes_for(pipeline, opts) { name: 'test build', stage: 'test', stage_idx: stage_index(opts[:stage]), - ref: 'master', user: build_user, project: @project, pipeline: pipeline, + ref: 'master', tag: false, user: build_user, project: @project, pipeline: pipeline, created_at: Time.now, updated_at: Time.now }.merge(opts) end -- cgit v1.2.1 From efef0be2352a7a2ca769c1db0560a76fbe36b9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 2 Aug 2016 19:35:48 -0400 Subject: Remove unnecessary index_projects_on_builds_enabled index from the projects table --- .../20160802010328_remove_builds_enable_index_on_projects.rb | 9 +++++++++ db/schema.rb | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb (limited to 'db') diff --git a/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb b/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb new file mode 100644 index 00000000000..5fd51cb65f1 --- /dev/null +++ b/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb @@ -0,0 +1,9 @@ +class RemoveBuildsEnableIndexOnProjects < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + remove_index :projects, column: :builds_enabled if index_exists?(:projects, :builds_enabled) + end +end diff --git a/db/schema.rb b/db/schema.rb index 5b35a528e71..dc28842758a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160726093600) do +ActiveRecord::Schema.define(version: 20160802010328) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -852,7 +852,6 @@ ActiveRecord::Schema.define(version: 20160726093600) do end add_index "projects", ["builds_enabled", "shared_runners_enabled"], name: "index_projects_on_builds_enabled_and_shared_runners_enabled", using: :btree - add_index "projects", ["builds_enabled"], name: "index_projects_on_builds_enabled", using: :btree add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree -- cgit v1.2.1 From 8e13162ae112c4c72ee269de0c7f58bfd675fa52 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 4 Aug 2016 09:55:02 +0530 Subject: Migrate protected branch access levels to match constants in `Gitlab::Access` - In the final round of review (!5081), we moved the protected branch access levels from Rails enums to constants from Gitlab::Access. - The migrations that moved us from the old data model (a single protected_branches table with developers_can_push and developers_can_merge flags) to the new one (separate tables for push_access_levels and merge_access_levels) was not updated. - These migrations still used 0 to mean "Masters" and 1 to mean "Developers" (matching the previous Rails enum), while Gitlab::Access uses 40 and 30 for these, respectively. - Once the migrations run, our data gets into a broken state. - We fix this by migrating all `0`s to `40` and all `1`s to `30`. - https://gitlab.com/gitlab-org/gitlab-ce/issues/20606#note_13561628 = Caveats = - In Gitlab::Access, 0 represents NO_ACCESS. When we run this migration, all protected branches with "No one" as an access level will be changed to "Masters" --- ...ve_from_developers_can_merge_to_protected_branches_merge_access.rb | 4 ++-- ...move_from_developers_can_push_to_protected_branches_push_access.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'db') diff --git a/db/migrate/20160705055254_move_from_developers_can_merge_to_protected_branches_merge_access.rb b/db/migrate/20160705055254_move_from_developers_can_merge_to_protected_branches_merge_access.rb index fa93936ced7..1db0df92bec 100644 --- a/db/migrate/20160705055254_move_from_developers_can_merge_to_protected_branches_merge_access.rb +++ b/db/migrate/20160705055254_move_from_developers_can_merge_to_protected_branches_merge_access.rb @@ -14,7 +14,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M def up execute <<-HEREDOC INSERT into protected_branch_merge_access_levels (protected_branch_id, access_level, created_at, updated_at) - SELECT id, (CASE WHEN developers_can_merge THEN 1 ELSE 0 END), now(), now() + SELECT id, (CASE WHEN developers_can_merge THEN 30 ELSE 40 END), now(), now() FROM protected_branches HEREDOC end @@ -23,7 +23,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M execute <<-HEREDOC UPDATE protected_branches SET developers_can_merge = TRUE WHERE id IN (SELECT protected_branch_id FROM protected_branch_merge_access_levels - WHERE access_level = 1); + WHERE access_level = 30); HEREDOC end end diff --git a/db/migrate/20160705055308_move_from_developers_can_push_to_protected_branches_push_access.rb b/db/migrate/20160705055308_move_from_developers_can_push_to_protected_branches_push_access.rb index 56f6159d1d8..5c3e189bb5b 100644 --- a/db/migrate/20160705055308_move_from_developers_can_push_to_protected_branches_push_access.rb +++ b/db/migrate/20160705055308_move_from_developers_can_push_to_protected_branches_push_access.rb @@ -14,7 +14,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig def up execute <<-HEREDOC INSERT into protected_branch_push_access_levels (protected_branch_id, access_level, created_at, updated_at) - SELECT id, (CASE WHEN developers_can_push THEN 1 ELSE 0 END), now(), now() + SELECT id, (CASE WHEN developers_can_push THEN 30 ELSE 40 END), now(), now() FROM protected_branches HEREDOC end @@ -23,7 +23,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig execute <<-HEREDOC UPDATE protected_branches SET developers_can_push = TRUE WHERE id IN (SELECT protected_branch_id FROM protected_branch_push_access_levels - WHERE access_level = 1); + WHERE access_level = 30); HEREDOC end end -- cgit v1.2.1 From 4d0461e29983630a653203a1e5c1a28dfcfeada5 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 4 Aug 2016 10:42:34 +0530 Subject: Fix `#down` for two protected branches-related migrations. - The migrations called `add_column_with_default` with a `null` option, which the Rails `add_column` method accepts. This fails because `add_column_with_default` expects an `allow_null` option instead. - The migrations have been fixed to use `allow_null`. --- ...20160705055809_remove_developers_can_push_from_protected_branches.rb | 2 +- ...0160705055813_remove_developers_can_merge_from_protected_branches.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'db') diff --git a/db/migrate/20160705055809_remove_developers_can_push_from_protected_branches.rb b/db/migrate/20160705055809_remove_developers_can_push_from_protected_branches.rb index f563f660ddf..52a9819c628 100644 --- a/db/migrate/20160705055809_remove_developers_can_push_from_protected_branches.rb +++ b/db/migrate/20160705055809_remove_developers_can_push_from_protected_branches.rb @@ -14,6 +14,6 @@ class RemoveDevelopersCanPushFromProtectedBranches < ActiveRecord::Migration end def down - add_column_with_default(:protected_branches, :developers_can_push, :boolean, default: false, null: false) + add_column_with_default(:protected_branches, :developers_can_push, :boolean, default: false, allow_null: false) end end diff --git a/db/migrate/20160705055813_remove_developers_can_merge_from_protected_branches.rb b/db/migrate/20160705055813_remove_developers_can_merge_from_protected_branches.rb index aa71e06d36e..4a7bde7f9f3 100644 --- a/db/migrate/20160705055813_remove_developers_can_merge_from_protected_branches.rb +++ b/db/migrate/20160705055813_remove_developers_can_merge_from_protected_branches.rb @@ -14,6 +14,6 @@ class RemoveDevelopersCanMergeFromProtectedBranches < ActiveRecord::Migration end def down - add_column_with_default(:protected_branches, :developers_can_merge, :boolean, default: false, null: false) + add_column_with_default(:protected_branches, :developers_can_merge, :boolean, default: false, allow_null: false) end end -- cgit v1.2.1 From f301d547c2a3ca2a3f1fd07f9ddc4eb451e70244 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 4 Aug 2016 15:27:53 +0100 Subject: Add a data migration to fix some missing timestamps in the members table (again) --- ...20160804150737_add_timestamps_to_members_again.rb | 20 ++++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160804150737_add_timestamps_to_members_again.rb (limited to 'db') diff --git a/db/migrate/20160804150737_add_timestamps_to_members_again.rb b/db/migrate/20160804150737_add_timestamps_to_members_again.rb new file mode 100644 index 00000000000..60f4e7af90f --- /dev/null +++ b/db/migrate/20160804150737_add_timestamps_to_members_again.rb @@ -0,0 +1,20 @@ +# rubocop:disable all +# 20141121133009_add_timestamps_to_members.rb was meant to ensure that all +# rows in the members table had created_at and updated_at set, following an +# error in a previous migration. This failed to set all rows in at least one +# case: https://gitlab.com/gitlab-org/gitlab-ce/issues/20568 +# +# Why this happened is lost in the mists of time, so repeat the SQL query +# without speculation, just in case more than one person was affected. +class AddTimestampsToMembersAgain < ActiveRecord::Migration + + def up + execute "UPDATE members SET created_at = NOW() WHERE created_at IS NULL" + execute "UPDATE members SET updated_at = NOW() WHERE updated_at IS NULL" + end + + def down + # no change + end + +end diff --git a/db/schema.rb b/db/schema.rb index dc28842758a..71980a6d51f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160802010328) do +ActiveRecord::Schema.define(version: 20160804150737) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.1 From 98260f36cf697665509b89288c4208007d8ad6ce Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 4 Aug 2016 17:01:47 +0100 Subject: Add missing DOWNTIME constant to the AddTimestampsToMembersAgain migration --- db/migrate/20160804150737_add_timestamps_to_members_again.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'db') diff --git a/db/migrate/20160804150737_add_timestamps_to_members_again.rb b/db/migrate/20160804150737_add_timestamps_to_members_again.rb index 60f4e7af90f..6691ba57fbb 100644 --- a/db/migrate/20160804150737_add_timestamps_to_members_again.rb +++ b/db/migrate/20160804150737_add_timestamps_to_members_again.rb @@ -7,6 +7,7 @@ # Why this happened is lost in the mists of time, so repeat the SQL query # without speculation, just in case more than one person was affected. class AddTimestampsToMembersAgain < ActiveRecord::Migration + DOWNTIME = false def up execute "UPDATE members SET created_at = NOW() WHERE created_at IS NULL" -- cgit v1.2.1 From 17dd3e89d5a43761e85d7af30ad083db6ca5834b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 10 Aug 2016 12:29:06 +0200 Subject: Remove trigram indexes for "ci_runners" These indexes are only used when you search for runners in the admin interface. This operation is so rarely used that it does not make sense to slow down every update in order to update the GIN trigram indexes. Removing these indexes should speed up queries such as those used for updating the last contact time of CI runners. Locally the timings of this query were reduced from ~50 ms to ~25 ms: UPDATE ci_runners SET updated_at = now(), contacted_at = now(); --- ...60810102349_remove_ci_runner_trigram_indexes.rb | 27 ++++++++++++++++++++++ db/schema.rb | 4 +--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20160810102349_remove_ci_runner_trigram_indexes.rb (limited to 'db') diff --git a/db/migrate/20160810102349_remove_ci_runner_trigram_indexes.rb b/db/migrate/20160810102349_remove_ci_runner_trigram_indexes.rb new file mode 100644 index 00000000000..0cfb637804b --- /dev/null +++ b/db/migrate/20160810102349_remove_ci_runner_trigram_indexes.rb @@ -0,0 +1,27 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveCiRunnerTrigramIndexes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + # Disabled for the "down" method so the indexes can be re-created concurrently. + disable_ddl_transaction! + + def up + return unless Gitlab::Database.postgresql? + + transaction do + execute 'DROP INDEX IF EXISTS index_ci_runners_on_token_trigram;' + execute 'DROP INDEX IF EXISTS index_ci_runners_on_description_trigram;' + end + end + + def down + return unless Gitlab::Database.postgresql? + + execute 'CREATE INDEX CONCURRENTLY index_ci_runners_on_token_trigram ON ci_runners USING gin(token gin_trgm_ops);' + execute 'CREATE INDEX CONCURRENTLY index_ci_runners_on_description_trigram ON ci_runners USING gin(description gin_trgm_ops);' + end +end diff --git a/db/schema.rb b/db/schema.rb index 71980a6d51f..b795eeaa23c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160804150737) do +ActiveRecord::Schema.define(version: 20160810102349) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -301,10 +301,8 @@ ActiveRecord::Schema.define(version: 20160804150737) do t.boolean "locked", default: false, null: false end - add_index "ci_runners", ["description"], name: "index_ci_runners_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "ci_runners", ["locked"], name: "index_ci_runners_on_locked", using: :btree add_index "ci_runners", ["token"], name: "index_ci_runners_on_token", using: :btree - add_index "ci_runners", ["token"], name: "index_ci_runners_on_token_trigram", using: :gin, opclasses: {"token"=>"gin_trgm_ops"} create_table "ci_services", force: :cascade do |t| t.string "type" -- cgit v1.2.1 From 7d39bc879d6dc4c0111b3c4ecb2d879034d8d36f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 10 Aug 2016 17:26:52 +0200 Subject: Remove various redundant indexes One can see which indexes are used in PostgreSQL by running the following query: SELECT relname as table_name, indexrelname as index_name, idx_scan, idx_tup_read, idx_tup_fetch, pg_size_pretty(pg_relation_size(indexrelname::regclass)) FROM pg_stat_all_indexes WHERE schemaname = 'public' AND "idx_scan" = 0 ORDER BY pg_relation_size(indexrelname::regclass) desc; Using this query I built a list of indexes that could be potentially removed. After checking every single one by hand to make sure they really aren't used I only found 1 index that _would_ be used. This was a GitLab GEO index (EE) specific that's currently not used simply because the table is empty. Apart from this one index all indexes could be removed. The migration also takes care of 6 composite indexes that can be replaced with a single column index, which in most cases was already present. For more information see gitlab-org/gitlab-ce#20767. --- .../20160810142633_remove_redundant_indexes.rb | 112 +++++++++++++++++++++ db/schema.rb | 56 +---------- 2 files changed, 116 insertions(+), 52 deletions(-) create mode 100644 db/migrate/20160810142633_remove_redundant_indexes.rb (limited to 'db') diff --git a/db/migrate/20160810142633_remove_redundant_indexes.rb b/db/migrate/20160810142633_remove_redundant_indexes.rb new file mode 100644 index 00000000000..8641c6ffa8f --- /dev/null +++ b/db/migrate/20160810142633_remove_redundant_indexes.rb @@ -0,0 +1,112 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveRedundantIndexes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + indexes = [ + [:ci_taggings, 'ci_taggings_idx'], + [:audit_events, 'index_audit_events_on_author_id'], + [:audit_events, 'index_audit_events_on_type'], + [:ci_builds, 'index_ci_builds_on_erased_by_id'], + [:ci_builds, 'index_ci_builds_on_project_id_and_commit_id'], + [:ci_builds, 'index_ci_builds_on_type'], + [:ci_commits, 'index_ci_commits_on_project_id'], + [:ci_commits, 'index_ci_commits_on_project_id_and_committed_at'], + [:ci_commits, 'index_ci_commits_on_project_id_and_committed_at_and_id'], + [:ci_commits, 'index_ci_commits_on_project_id_and_sha'], + [:ci_commits, 'index_ci_commits_on_sha'], + [:ci_events, 'index_ci_events_on_created_at'], + [:ci_events, 'index_ci_events_on_is_admin'], + [:ci_events, 'index_ci_events_on_project_id'], + [:ci_jobs, 'index_ci_jobs_on_deleted_at'], + [:ci_jobs, 'index_ci_jobs_on_project_id'], + [:ci_projects, 'index_ci_projects_on_gitlab_id'], + [:ci_projects, 'index_ci_projects_on_shared_runners_enabled'], + [:ci_services, 'index_ci_services_on_project_id'], + [:ci_sessions, 'index_ci_sessions_on_session_id'], + [:ci_sessions, 'index_ci_sessions_on_updated_at'], + [:ci_tags, 'index_ci_tags_on_name'], + [:ci_triggers, 'index_ci_triggers_on_deleted_at'], + [:identities, 'index_identities_on_created_at_and_id'], + [:issues, 'index_issues_on_title'], + [:keys, 'index_keys_on_created_at_and_id'], + [:members, 'index_members_on_created_at_and_id'], + [:members, 'index_members_on_type'], + [:milestones, 'index_milestones_on_created_at_and_id'], + [:namespaces, 'index_namespaces_on_visibility_level'], + [:projects, 'index_projects_on_builds_enabled_and_shared_runners_enabled'], + [:services, 'index_services_on_category'], + [:services, 'index_services_on_created_at_and_id'], + [:services, 'index_services_on_default'], + [:snippets, 'index_snippets_on_created_at'], + [:snippets, 'index_snippets_on_created_at_and_id'], + [:todos, 'index_todos_on_state'], + [:web_hooks, 'index_web_hooks_on_created_at_and_id'], + + # These indexes _may_ be used but they can be replaced by other existing + # indexes. + + # There's already a composite index on (project_id, iid) which means that + # a separate index for _just_ project_id is not needed. + [:issues, 'index_issues_on_project_id'], + + # These are all composite indexes for the columns (created_at, id). In all + # these cases there's already a standalone index for "created_at" which + # can be used instead. + # + # Because the "id" column of these composite indexes is never needed (due + # to "id" already being indexed as its a primary key) these composite + # indexes are useless. + [:issues, 'index_issues_on_created_at_and_id'], + [:merge_requests, 'index_merge_requests_on_created_at_and_id'], + [:namespaces, 'index_namespaces_on_created_at_and_id'], + [:notes, 'index_notes_on_created_at_and_id'], + [:projects, 'index_projects_on_created_at_and_id'], + [:users, 'index_users_on_created_at_and_id'], + ] + + transaction do + indexes.each do |(table, index)| + remove_index(table, name: index) if index_exists_by_name?(table, index) + end + end + + add_concurrent_index(:users, :created_at) + add_concurrent_index(:projects, :created_at) + add_concurrent_index(:namespaces, :created_at) + end + + def down + # We're only restoring the composite indexes that could be replaced with + # individual ones, just in case somebody would ever want to revert. + transaction do + remove_index(:users, :created_at) + remove_index(:projects, :created_at) + remove_index(:namespaces, :created_at) + end + + [:issues, :merge_requests, :namespaces, :notes, :projects, :users].each do |table| + add_concurrent_index(table, [:created_at, :id], + name: "index_#{table}_on_created_at_and_id") + end + end + + # Rails' index_exists? doesn't work when you only give it a table and index + # name. As such we have to use some extra code to check if an index exists for + # a given name. + def index_exists_by_name?(table, index) + indexes_for_table[table].include?(index) + end + + def indexes_for_table + @indexes_for_table ||= Hash.new do |hash, table_name| + hash[table_name] = indexes(table_name).map(&:name) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b795eeaa23c..059c923bb93 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160810102349) do +ActiveRecord::Schema.define(version: 20160810142633) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -102,9 +102,7 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "updated_at" end - add_index "audit_events", ["author_id"], name: "index_audit_events_on_author_id", using: :btree add_index "audit_events", ["entity_id", "entity_type"], name: "index_audit_events_on_entity_id_and_entity_type", using: :btree - add_index "audit_events", ["type"], name: "index_audit_events_on_type", using: :btree create_table "award_emoji", force: :cascade do |t| t.string "name" @@ -179,13 +177,10 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "ci_builds", ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree add_index "ci_builds", ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref", using: :btree add_index "ci_builds", ["commit_id"], name: "index_ci_builds_on_commit_id", using: :btree - add_index "ci_builds", ["erased_by_id"], name: "index_ci_builds_on_erased_by_id", using: :btree add_index "ci_builds", ["gl_project_id"], name: "index_ci_builds_on_gl_project_id", using: :btree - add_index "ci_builds", ["project_id", "commit_id"], name: "index_ci_builds_on_project_id_and_commit_id", using: :btree add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree add_index "ci_builds", ["status"], name: "index_ci_builds_on_status", using: :btree - add_index "ci_builds", ["type"], name: "index_ci_builds_on_type", using: :btree create_table "ci_commits", force: :cascade do |t| t.integer "project_id" @@ -209,11 +204,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "ci_commits", ["gl_project_id", "sha"], name: "index_ci_commits_on_gl_project_id_and_sha", using: :btree add_index "ci_commits", ["gl_project_id", "status"], name: "index_ci_commits_on_gl_project_id_and_status", using: :btree add_index "ci_commits", ["gl_project_id"], name: "index_ci_commits_on_gl_project_id", using: :btree - add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree - add_index "ci_commits", ["project_id", "committed_at"], name: "index_ci_commits_on_project_id_and_committed_at", using: :btree - add_index "ci_commits", ["project_id", "sha"], name: "index_ci_commits_on_project_id_and_sha", using: :btree - add_index "ci_commits", ["project_id"], name: "index_ci_commits_on_project_id", using: :btree - add_index "ci_commits", ["sha"], name: "index_ci_commits_on_sha", using: :btree add_index "ci_commits", ["status"], name: "index_ci_commits_on_status", using: :btree add_index "ci_commits", ["user_id"], name: "index_ci_commits_on_user_id", using: :btree @@ -226,10 +216,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "updated_at" end - add_index "ci_events", ["created_at"], name: "index_ci_events_on_created_at", using: :btree - add_index "ci_events", ["is_admin"], name: "index_ci_events_on_is_admin", using: :btree - add_index "ci_events", ["project_id"], name: "index_ci_events_on_project_id", using: :btree - create_table "ci_jobs", force: :cascade do |t| t.integer "project_id", null: false t.text "commands" @@ -244,9 +230,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "deleted_at" end - add_index "ci_jobs", ["deleted_at"], name: "index_ci_jobs_on_deleted_at", using: :btree - add_index "ci_jobs", ["project_id"], name: "index_ci_jobs_on_project_id", using: :btree - create_table "ci_projects", force: :cascade do |t| t.string "name" t.integer "timeout", default: 3600, null: false @@ -270,9 +253,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.text "generated_yaml_config" end - add_index "ci_projects", ["gitlab_id"], name: "index_ci_projects_on_gitlab_id", using: :btree - add_index "ci_projects", ["shared_runners_enabled"], name: "index_ci_projects_on_shared_runners_enabled", using: :btree - create_table "ci_runner_projects", force: :cascade do |t| t.integer "runner_id", null: false t.integer "project_id" @@ -314,8 +294,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.text "properties" end - add_index "ci_services", ["project_id"], name: "index_ci_services_on_project_id", using: :btree - create_table "ci_sessions", force: :cascade do |t| t.string "session_id", null: false t.text "data" @@ -323,9 +301,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "updated_at" end - add_index "ci_sessions", ["session_id"], name: "index_ci_sessions_on_session_id", using: :btree - add_index "ci_sessions", ["updated_at"], name: "index_ci_sessions_on_updated_at", using: :btree - create_table "ci_taggings", force: :cascade do |t| t.integer "tag_id" t.integer "taggable_id" @@ -336,7 +311,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "created_at" end - add_index "ci_taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "ci_taggings_idx", unique: true, using: :btree add_index "ci_taggings", ["taggable_id", "taggable_type", "context"], name: "index_ci_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "ci_tags", force: :cascade do |t| @@ -344,8 +318,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.integer "taggings_count", default: 0 end - add_index "ci_tags", ["name"], name: "index_ci_tags_on_name", unique: true, using: :btree - create_table "ci_trigger_requests", force: :cascade do |t| t.integer "trigger_id", null: false t.text "variables" @@ -363,7 +335,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.integer "gl_project_id" end - add_index "ci_triggers", ["deleted_at"], name: "index_ci_triggers_on_deleted_at", using: :btree add_index "ci_triggers", ["gl_project_id"], name: "index_ci_triggers_on_gl_project_id", using: :btree create_table "ci_variables", force: :cascade do |t| @@ -469,7 +440,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.datetime "updated_at" end - add_index "identities", ["created_at", "id"], name: "index_identities_on_created_at_and_id", using: :btree add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree create_table "issues", force: :cascade do |t| @@ -495,16 +465,13 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree add_index "issues", ["author_id"], name: "index_issues_on_author_id", using: :btree add_index "issues", ["confidential"], name: "index_issues_on_confidential", using: :btree - add_index "issues", ["created_at", "id"], name: "index_issues_on_created_at_and_id", using: :btree add_index "issues", ["created_at"], name: "index_issues_on_created_at", using: :btree add_index "issues", ["deleted_at"], name: "index_issues_on_deleted_at", using: :btree add_index "issues", ["description"], name: "index_issues_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "issues", ["due_date"], name: "index_issues_on_due_date", using: :btree add_index "issues", ["milestone_id"], name: "index_issues_on_milestone_id", using: :btree add_index "issues", ["project_id", "iid"], name: "index_issues_on_project_id_and_iid", unique: true, using: :btree - add_index "issues", ["project_id"], name: "index_issues_on_project_id", using: :btree add_index "issues", ["state"], name: "index_issues_on_state", using: :btree - add_index "issues", ["title"], name: "index_issues_on_title", using: :btree add_index "issues", ["title"], name: "index_issues_on_title_trigram", using: :gin, opclasses: {"title"=>"gin_trgm_ops"} create_table "keys", force: :cascade do |t| @@ -518,7 +485,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.boolean "public", default: false, null: false end - add_index "keys", ["created_at", "id"], name: "index_keys_on_created_at_and_id", using: :btree add_index "keys", ["fingerprint"], name: "index_keys_on_fingerprint", unique: true, using: :btree add_index "keys", ["user_id"], name: "index_keys_on_user_id", using: :btree @@ -583,11 +549,9 @@ ActiveRecord::Schema.define(version: 20160810102349) do end add_index "members", ["access_level"], name: "index_members_on_access_level", using: :btree - add_index "members", ["created_at", "id"], name: "index_members_on_created_at_and_id", using: :btree add_index "members", ["invite_token"], name: "index_members_on_invite_token", unique: true, using: :btree add_index "members", ["requested_at"], name: "index_members_on_requested_at", using: :btree add_index "members", ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type", using: :btree - add_index "members", ["type"], name: "index_members_on_type", using: :btree add_index "members", ["user_id"], name: "index_members_on_user_id", using: :btree create_table "merge_request_diffs", force: :cascade do |t| @@ -634,7 +598,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree add_index "merge_requests", ["author_id"], name: "index_merge_requests_on_author_id", using: :btree - add_index "merge_requests", ["created_at", "id"], name: "index_merge_requests_on_created_at_and_id", using: :btree add_index "merge_requests", ["created_at"], name: "index_merge_requests_on_created_at", using: :btree add_index "merge_requests", ["deleted_at"], name: "index_merge_requests_on_deleted_at", using: :btree add_index "merge_requests", ["description"], name: "index_merge_requests_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} @@ -657,7 +620,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.integer "iid" end - add_index "milestones", ["created_at", "id"], name: "index_milestones_on_created_at_and_id", using: :btree add_index "milestones", ["description"], name: "index_milestones_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "milestones", ["due_date"], name: "index_milestones_on_due_date", using: :btree add_index "milestones", ["project_id", "iid"], name: "index_milestones_on_project_id_and_iid", unique: true, using: :btree @@ -679,14 +641,13 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.boolean "request_access_enabled", default: true, null: false end - add_index "namespaces", ["created_at", "id"], name: "index_namespaces_on_created_at_and_id", using: :btree + add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree add_index "namespaces", ["path"], name: "index_namespaces_on_path", unique: true, using: :btree add_index "namespaces", ["path"], name: "index_namespaces_on_path_trigram", using: :gin, opclasses: {"path"=>"gin_trgm_ops"} add_index "namespaces", ["type"], name: "index_namespaces_on_type", using: :btree - add_index "namespaces", ["visibility_level"], name: "index_namespaces_on_visibility_level", using: :btree create_table "notes", force: :cascade do |t| t.text "note" @@ -709,7 +670,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "notes", ["author_id"], name: "index_notes_on_author_id", using: :btree add_index "notes", ["commit_id"], name: "index_notes_on_commit_id", using: :btree - add_index "notes", ["created_at", "id"], name: "index_notes_on_created_at_and_id", using: :btree add_index "notes", ["created_at"], name: "index_notes_on_created_at", using: :btree add_index "notes", ["line_code"], name: "index_notes_on_line_code", using: :btree add_index "notes", ["note"], name: "index_notes_on_note_trigram", using: :gin, opclasses: {"note"=>"gin_trgm_ops"} @@ -849,9 +809,8 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.boolean "request_access_enabled", default: true, null: false end - add_index "projects", ["builds_enabled", "shared_runners_enabled"], name: "index_projects_on_builds_enabled_and_shared_runners_enabled", using: :btree add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree - add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree + add_index "projects", ["created_at"], name: "index_projects_on_created_at", using: :btree add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree @@ -937,9 +896,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.boolean "wiki_page_events", default: true end - add_index "services", ["category"], name: "index_services_on_category", using: :btree - add_index "services", ["created_at", "id"], name: "index_services_on_created_at_and_id", using: :btree - add_index "services", ["default"], name: "index_services_on_default", using: :btree add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree add_index "services", ["template"], name: "index_services_on_template", using: :btree @@ -956,8 +912,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do end add_index "snippets", ["author_id"], name: "index_snippets_on_author_id", using: :btree - add_index "snippets", ["created_at", "id"], name: "index_snippets_on_created_at_and_id", using: :btree - add_index "snippets", ["created_at"], name: "index_snippets_on_created_at", using: :btree add_index "snippets", ["file_name"], name: "index_snippets_on_file_name_trigram", using: :gin, opclasses: {"file_name"=>"gin_trgm_ops"} add_index "snippets", ["project_id"], name: "index_snippets_on_project_id", using: :btree add_index "snippets", ["title"], name: "index_snippets_on_title_trigram", using: :gin, opclasses: {"title"=>"gin_trgm_ops"} @@ -1026,7 +980,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "todos", ["commit_id"], name: "index_todos_on_commit_id", using: :btree add_index "todos", ["note_id"], name: "index_todos_on_note_id", using: :btree add_index "todos", ["project_id"], name: "index_todos_on_project_id", using: :btree - add_index "todos", ["state"], name: "index_todos_on_state", using: :btree add_index "todos", ["target_type", "target_id"], name: "index_todos_on_target_type_and_target_id", using: :btree add_index "todos", ["user_id"], name: "index_todos_on_user_id", using: :btree @@ -1106,7 +1059,7 @@ ActiveRecord::Schema.define(version: 20160810102349) do add_index "users", ["admin"], name: "index_users_on_admin", using: :btree add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["created_at", "id"], name: "index_users_on_created_at_and_id", using: :btree + add_index "users", ["created_at"], name: "index_users_on_created_at", using: :btree add_index "users", ["current_sign_in_at"], name: "index_users_on_current_sign_in_at", using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email_trigram", using: :gin, opclasses: {"email"=>"gin_trgm_ops"} @@ -1146,7 +1099,6 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.string "token" end - add_index "web_hooks", ["created_at", "id"], name: "index_web_hooks_on_created_at_and_id", using: :btree add_index "web_hooks", ["project_id"], name: "index_web_hooks_on_project_id", using: :btree add_foreign_key "personal_access_tokens", "users" -- cgit v1.2.1 From 39203f1adfc6fee3eca50f0cab99ffc597865200 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 11 Aug 2016 15:22:35 +0200 Subject: Pre-create all builds for Pipeline when a trigger is received This change simplifies a Pipeline processing by introducing a special new status: created. This status is used for all builds that are created for a pipeline. We are then processing next stages and queueing some of the builds (created -> pending) or skipping them (created -> skipped). This makes it possible to simplify and solve a few ordering problems with how previously builds were scheduled. This also allows us to visualise a full pipeline (with created builds). This also removes an after_touch used for updating a pipeline state parameters. Right now in various places we explicitly call a reload_status! on pipeline to force it to be updated and saved. --- db/migrate/20160716115711_add_queued_at_to_ci_builds.rb | 9 +++++++++ db/schema.rb | 1 + 2 files changed, 10 insertions(+) create mode 100644 db/migrate/20160716115711_add_queued_at_to_ci_builds.rb (limited to 'db') diff --git a/db/migrate/20160716115711_add_queued_at_to_ci_builds.rb b/db/migrate/20160716115711_add_queued_at_to_ci_builds.rb new file mode 100644 index 00000000000..756910a1fa0 --- /dev/null +++ b/db/migrate/20160716115711_add_queued_at_to_ci_builds.rb @@ -0,0 +1,9 @@ +class AddQueuedAtToCiBuilds < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column :ci_builds, :queued_at, :timestamp + end +end diff --git a/db/schema.rb b/db/schema.rb index b795eeaa23c..e0c6178a5a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -172,6 +172,7 @@ ActiveRecord::Schema.define(version: 20160810102349) do t.integer "artifacts_size" t.string "when" t.text "yaml_variables" + t.datetime "queued_at" end add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree -- cgit v1.2.1 From ffa75a497a23bf6f87de626fee08ff4538a12587 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 11 Aug 2016 17:23:07 +0200 Subject: Remove stage parameter from send payload --- db/schema.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'db') diff --git a/db/schema.rb b/db/schema.rb index 6c85e1e9dba..5b901b17265 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -895,6 +895,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.string "category", default: "common", null: false t.boolean "default", default: false t.boolean "wiki_page_events", default: true + t.boolean "pipeline_events", default: false, null: false end add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree @@ -1098,6 +1099,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.boolean "build_events", default: false, null: false t.boolean "wiki_page_events", default: false, null: false t.string "token" + t.boolean "pipeline_events", default: false, null: false end add_index "web_hooks", ["project_id"], name: "index_web_hooks_on_project_id", using: :btree -- cgit v1.2.1 From cb8a425ba42e9be23b8712ed29b1db2dcc6bd139 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 28 May 2016 19:54:17 -0700 Subject: Fix bug where destroying a namespace would not always destroy projects There is a race condition in DestroyGroupService now that projects are deleted asynchronously: 1. User attempts to delete group 2. DestroyGroupService iterates through all projects and schedules a Sidekiq job to delete each Project 3. DestroyGroupService destroys the Group, leaving all its projects without a namespace 4. Projects::DestroyService runs later but the can?(current_user, :remove_project) is `false` because the user no longer has permission to destroy projects with no namespace. 5. This leaves the project in pending_delete state with no namespace/group. Projects without a namespace or group also adds another problem: it's not possible to destroy the container registry tags, since container_registry_path_with_namespace is the wrong value. The fix is to destroy the group asynchronously and to run execute directly on Projects::DestroyService. Closes #17893 --- db/migrate/20140407135544_fix_namespaces.rb | 10 ++++++++-- db/migrate/20160805041956_add_deleted_at_to_namespaces.rb | 12 ++++++++++++ db/schema.rb | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160805041956_add_deleted_at_to_namespaces.rb (limited to 'db') diff --git a/db/migrate/20140407135544_fix_namespaces.rb b/db/migrate/20140407135544_fix_namespaces.rb index 91374966698..0026ce645a6 100644 --- a/db/migrate/20140407135544_fix_namespaces.rb +++ b/db/migrate/20140407135544_fix_namespaces.rb @@ -1,8 +1,14 @@ # rubocop:disable all class FixNamespaces < ActiveRecord::Migration + DOWNTIME = false + def up - Namespace.where('name <> path and type is null').each do |namespace| - namespace.update_attribute(:name, namespace.path) + namespaces = exec_query('SELECT id, path FROM namespaces WHERE name <> path and type is null') + + namespaces.each do |row| + id = row['id'] + path = row['path'] + exec_query("UPDATE namespaces SET name = '#{path}' WHERE id = #{id}") end end diff --git a/db/migrate/20160805041956_add_deleted_at_to_namespaces.rb b/db/migrate/20160805041956_add_deleted_at_to_namespaces.rb new file mode 100644 index 00000000000..a853de3abfb --- /dev/null +++ b/db/migrate/20160805041956_add_deleted_at_to_namespaces.rb @@ -0,0 +1,12 @@ +class AddDeletedAtToNamespaces < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_column :namespaces, :deleted_at, :datetime + add_concurrent_index :namespaces, :deleted_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c85e1e9dba..1de2cdcf026 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -640,9 +640,11 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.boolean "share_with_group_lock", default: false t.integer "visibility_level", default: 20, null: false t.boolean "request_access_enabled", default: true, null: false + t.datetime "deleted_at" end add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree + add_index "namespaces", ["deleted_at"], name: "index_namespaces_on_deleted_at", using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree -- cgit v1.2.1 From 07fc2f852a0b4136b6d97c1d9773819c47e7e8e7 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 9 Aug 2016 15:11:14 +0200 Subject: Method names changed to #includes_commit? --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'db') diff --git a/db/schema.rb b/db/schema.rb index 6c85e1e9dba..1aa4e8a73d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -589,12 +589,12 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.datetime "locked_at" t.integer "updated_by_id" t.string "merge_error" - t.text "merge_params" t.boolean "merge_when_build_succeeds", default: false, null: false t.integer "merge_user_id" t.string "merge_commit_sha" t.datetime "deleted_at" t.string "in_progress_merge_commit_sha" + t.text "merge_params" end add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree -- cgit v1.2.1 From 95419679f23f0628d1885dd9656cc159e9d55ea9 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 27 Jul 2016 19:03:06 -0500 Subject: Lay the ground works to submit information to Akismet - New concern `AkismetSubmittable` to allow issues and other `Spammable` models to be submitted to Akismet. - New model `UserAgentDetail` to store information needed for Akismet. - Services needed for their creation and tests. --- db/migrate/20160727163552_create_user_agent_details.rb | 12 ++++++++++++ db/schema.rb | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 db/migrate/20160727163552_create_user_agent_details.rb (limited to 'db') diff --git a/db/migrate/20160727163552_create_user_agent_details.rb b/db/migrate/20160727163552_create_user_agent_details.rb new file mode 100644 index 00000000000..05c21a476fa --- /dev/null +++ b/db/migrate/20160727163552_create_user_agent_details.rb @@ -0,0 +1,12 @@ +class CreateUserAgentDetails < ActiveRecord::Migration + def change + create_table :user_agent_details do |t| + t.string :user_agent, null: false + t.string :ip_address, null: false + t.integer :subject_id, null: false + t.string :subject_type, null: false + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f008a6bd7a7..2e5ffac5935 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -999,6 +999,15 @@ ActiveRecord::Schema.define(version: 20160810142633) do add_index "u2f_registrations", ["key_handle"], name: "index_u2f_registrations_on_key_handle", using: :btree add_index "u2f_registrations", ["user_id"], name: "index_u2f_registrations_on_user_id", using: :btree + create_table "user_agent_details", force: :cascade do |t| + t.string "user_agent", null: false + t.string "ip_address", null: false + t.integer "subject_id", null: false + t.string "subject_type", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false -- cgit v1.2.1 From 64ab2b3d9f10366249c03a6bcf5e8b1d20010d8f Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Fri, 29 Jul 2016 23:18:32 -0500 Subject: Refactored spam related code even further - Removed unnecessary column from `SpamLog` - Moved creation of SpamLogs out of its own service and into SpamCheckService - Simplified code in SpamCheckService. - Moved move spam related code into Spammable concern --- ...60729173930_remove_project_id_from_spam_logs.rb | 29 ++++++++++++++++++++++ db/schema.rb | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160729173930_remove_project_id_from_spam_logs.rb (limited to 'db') diff --git a/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb b/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb new file mode 100644 index 00000000000..5950874d5af --- /dev/null +++ b/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb @@ -0,0 +1,29 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveProjectIdFromSpamLogs < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = true + + # When a migration requires downtime you **must** uncomment the following + # constant and define a short and easy to understand explanation as to why the + # migration requires downtime. + DOWNTIME_REASON = 'Removing a table that contains data that is not used anywhere.' + + # When using the methods "add_concurrent_index" or "add_column_with_default" + # you must disable the use of transactions as these methods can not run in an + # existing transaction. When using "add_concurrent_index" make sure that this + # method is the _only_ method called in the migration, any other changes + # should go in a separate migration. This ensures that upon failure _only_ the + # index creation fails and can be retried or reverted easily. + # + # To disable transactions uncomment the following line and remove these + # comments: + # disable_ddl_transaction! + + def change + remove_column :spam_logs, :project_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e5ffac5935..cc881e54763 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -926,7 +926,6 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.string "source_ip" t.string "user_agent" t.boolean "via_api" - t.integer "project_id" t.string "noteable_type" t.string "title" t.text "description" -- cgit v1.2.1 From abf2dcd25c4a176801314872733ede91297d1ab0 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 1 Aug 2016 12:14:03 -0500 Subject: Allow `SpamLog` to be submitted as ham - Added `submitted_as_ham` to `SpamLog` to mark which logs have been submitted to Akismet. - Added routes and controller action. --- ...160801163709_add_submitted_as_ham_to_spam_logs.rb | 20 ++++++++++++++++++++ db/schema.rb | 1 + 2 files changed, 21 insertions(+) create mode 100644 db/migrate/20160801163709_add_submitted_as_ham_to_spam_logs.rb (limited to 'db') diff --git a/db/migrate/20160801163709_add_submitted_as_ham_to_spam_logs.rb b/db/migrate/20160801163709_add_submitted_as_ham_to_spam_logs.rb new file mode 100644 index 00000000000..296f1dfac7b --- /dev/null +++ b/db/migrate/20160801163709_add_submitted_as_ham_to_spam_logs.rb @@ -0,0 +1,20 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddSubmittedAsHamToSpamLogs < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + # When a migration requires downtime you **must** uncomment the following + # constant and define a short and easy to understand explanation as to why the + # migration requires downtime. + # DOWNTIME_REASON = '' + + disable_ddl_transaction! + + def change + add_column_with_default :spam_logs, :submitted_as_ham, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index cc881e54763..355eed13b68 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -931,6 +931,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "submitted_as_ham", default: false, null: false end create_table "subscriptions", force: :cascade do |t| -- cgit v1.2.1 From 96399a81cbb2e8a0f666241eeaff7cc784c26983 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 2 Aug 2016 16:21:57 -0500 Subject: Allow `Issue` to be submitted as spam - Added controller actions as reusable concerns - Added controller tests --- db/migrate/20160727163552_create_user_agent_details.rb | 1 + db/schema.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'db') diff --git a/db/migrate/20160727163552_create_user_agent_details.rb b/db/migrate/20160727163552_create_user_agent_details.rb index 05c21a476fa..f9a02f310da 100644 --- a/db/migrate/20160727163552_create_user_agent_details.rb +++ b/db/migrate/20160727163552_create_user_agent_details.rb @@ -5,6 +5,7 @@ class CreateUserAgentDetails < ActiveRecord::Migration t.string :ip_address, null: false t.integer :subject_id, null: false t.string :subject_type, null: false + t.boolean :submitted, default: false t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 355eed13b68..5ac08099e90 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1004,6 +1004,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.string "ip_address", null: false t.integer "subject_id", null: false t.string "subject_type", null: false + t.boolean "submitted", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end -- cgit v1.2.1 From 43e756d4eafd79f4d2f366b646ebb94af78b5a4c Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Fri, 5 Aug 2016 17:10:08 -0500 Subject: Refactored AkismetHelper into AkismetService and cleaned up `Spammable` - Refactored SpamCheckService into SpamService --- db/migrate/20160727163552_create_user_agent_details.rb | 5 +++++ db/migrate/20160729173930_remove_project_id_from_spam_logs.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'db') diff --git a/db/migrate/20160727163552_create_user_agent_details.rb b/db/migrate/20160727163552_create_user_agent_details.rb index f9a02f310da..6677f5e80ba 100644 --- a/db/migrate/20160727163552_create_user_agent_details.rb +++ b/db/migrate/20160727163552_create_user_agent_details.rb @@ -1,4 +1,9 @@ class CreateUserAgentDetails < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + def change create_table :user_agent_details do |t| t.string :user_agent, null: false diff --git a/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb b/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb index 5950874d5af..e28ab31d629 100644 --- a/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb +++ b/db/migrate/20160729173930_remove_project_id_from_spam_logs.rb @@ -10,7 +10,7 @@ class RemoveProjectIdFromSpamLogs < ActiveRecord::Migration # When a migration requires downtime you **must** uncomment the following # constant and define a short and easy to understand explanation as to why the # migration requires downtime. - DOWNTIME_REASON = 'Removing a table that contains data that is not used anywhere.' + DOWNTIME_REASON = 'Removing a column that contains data that is not used anywhere.' # When using the methods "add_concurrent_index" or "add_column_with_default" # you must disable the use of transactions as these methods can not run in an -- cgit v1.2.1 From 1b0aa72d71b1900e4a6254ebdf9af97c7377eda2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 15 Aug 2016 14:06:44 +0200 Subject: Fix pipeline and build seeds in development environment When we depend on state machine events in seeds, it is likely that we will break fixtures from time to time because when transition rules change, using events most likely invalidates some objects in seeds. --- db/fixtures/development/14_builds.rb | 59 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'db') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index e65abe4ef77..6441a036e75 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,5 +1,21 @@ class Gitlab::Seeder::Builds STAGES = %w[build notify_build test notify_test deploy notify_deploy] + BUILDS = [ + { name: 'build:linux', stage: 'build', status: :success }, + { name: 'build:osx', stage: 'build', status: :success }, + { name: 'slack post build', stage: 'notify_build', status: :success }, + { name: 'rspec:linux', stage: 'test', status: :success }, + { name: 'rspec:windows', stage: 'test', status: :success }, + { name: 'rspec:windows', stage: 'test', status: :success }, + { name: 'rspec:osx', stage: 'test', status_event: :success }, + { name: 'spinach:linux', stage: 'test', status: :pending }, + { name: 'spinach:osx', stage: 'test', status: :canceled }, + { name: 'cucumber:linux', stage: 'test', status: :running }, + { name: 'cucumber:osx', stage: 'test', status: :failed }, + { name: 'slack post test', stage: 'notify_test', status: :success }, + { name: 'staging', stage: 'deploy', environment: 'staging', status: :success }, + { name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :success }, + ] def initialize(project) @project = project @@ -8,25 +24,7 @@ class Gitlab::Seeder::Builds def seed! pipelines.each do |pipeline| begin - build_create!(pipeline, name: 'build:linux', stage: 'build', status_event: :success) - build_create!(pipeline, name: 'build:osx', stage: 'build', status_event: :success) - - build_create!(pipeline, name: 'slack post build', stage: 'notify_build', status_event: :success) - - build_create!(pipeline, name: 'rspec:linux', stage: 'test', status_event: :success) - build_create!(pipeline, name: 'rspec:windows', stage: 'test', status_event: :success) - build_create!(pipeline, name: 'rspec:windows', stage: 'test', status_event: :success) - build_create!(pipeline, name: 'rspec:osx', stage: 'test', status_event: :success) - build_create!(pipeline, name: 'spinach:linux', stage: 'test', status: :pending) - build_create!(pipeline, name: 'spinach:osx', stage: 'test', status_event: :cancel) - build_create!(pipeline, name: 'cucumber:linux', stage: 'test', status_event: :run) - build_create!(pipeline, name: 'cucumber:osx', stage: 'test', status_event: :drop) - - build_create!(pipeline, name: 'slack post test', stage: 'notify_test', status_event: :success) - - build_create!(pipeline, name: 'staging', stage: 'deploy', environment: 'staging', status_event: :success) - build_create!(pipeline, name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :success) - + BUILDS.each { |opts| build_create!(pipeline, opts) } commit_status_create!(pipeline, name: 'jenkins', status: :success) print '.' @@ -48,21 +46,22 @@ class Gitlab::Seeder::Builds def build_create!(pipeline, opts = {}) attributes = build_attributes_for(pipeline, opts) - build = Ci::Build.create!(attributes) - if opts[:name].start_with?('build') - artifacts_cache_file(artifacts_archive_path) do |file| - build.artifacts_file = file - end + Ci::Build.create!(attributes) do |build| + if opts[:name].start_with?('build') + artifacts_cache_file(artifacts_archive_path) do |file| + build.artifacts_file = file + end - artifacts_cache_file(artifacts_metadata_path) do |file| - build.artifacts_metadata = file + artifacts_cache_file(artifacts_metadata_path) do |file| + build.artifacts_metadata = file + end end - end - if %w(running success failed).include?(build.status) - # We need to set build trace after saving a build (id required) - build.trace = FFaker::Lorem.paragraphs(6).join("\n\n") + if %w(running success failed).include?(build.status) + # We need to set build trace after saving a build (id required) + build.trace = FFaker::Lorem.paragraphs(6).join("\n\n") + end end end -- cgit v1.2.1 From 5994c11910822463faeabb7b5f11d6529036db9d Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 9 Aug 2016 12:43:47 -0500 Subject: Further refactor and syntax fixes. --- db/migrate/20160727163552_create_user_agent_details.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'db') diff --git a/db/migrate/20160727163552_create_user_agent_details.rb b/db/migrate/20160727163552_create_user_agent_details.rb index 6677f5e80ba..ed4ccfedc0a 100644 --- a/db/migrate/20160727163552_create_user_agent_details.rb +++ b/db/migrate/20160727163552_create_user_agent_details.rb @@ -10,7 +10,7 @@ class CreateUserAgentDetails < ActiveRecord::Migration t.string :ip_address, null: false t.integer :subject_id, null: false t.string :subject_type, null: false - t.boolean :submitted, default: false + t.boolean :submitted, default: false, null: false t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 5ac08099e90..52ba60ace11 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1004,7 +1004,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.string "ip_address", null: false t.integer "subject_id", null: false t.string "subject_type", null: false - t.boolean "submitted", default: false + t.boolean "submitted", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end -- cgit v1.2.1 From bcb3937da8fbba5b6a83ba092079444d993a5696 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 16 Aug 2016 16:18:44 +0200 Subject: Update fixtures to make development testing easier --- db/fixtures/development/14_builds.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'db') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 6441a036e75..0d493fa1c3c 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -26,24 +26,44 @@ class Gitlab::Seeder::Builds begin BUILDS.each { |opts| build_create!(pipeline, opts) } commit_status_create!(pipeline, name: 'jenkins', status: :success) - print '.' rescue ActiveRecord::RecordInvalid print 'F' + ensure + pipeline.build_updated end end end def pipelines - commits = @project.repository.commits('master', limit: 5) - commits_sha = commits.map { |commit| commit.raw.id } - commits_sha.map do |sha| - @project.ensure_pipeline(sha, 'master') - end + master_pipelines + merge_request_pipelines + end + + def master_pipelines + create_pipelines_for(@project, 'master') rescue [] end + def merge_request_pipelines + @project.merge_requests.last(5).map do |merge_request| + create_pipelines(merge_request.source_project, merge_request.source_branch, merge_request.commits.last(5)) + end.flatten + rescue + [] + end + + def create_pipelines_for(project, ref) + commits = project.repository.commits(ref, limit: 5) + create_pipelines(project, ref, commits) + end + + def create_pipelines(project, ref, commits) + commits.map do |commit| + project.pipelines.create(sha: commit.id, ref: ref) + end + end + def build_create!(pipeline, opts = {}) attributes = build_attributes_for(pipeline, opts) -- cgit v1.2.1 From f52f62d7aec168b3b8c291cdb81f64501bd80e5a Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 16 Aug 2016 16:18:44 +0200 Subject: Update fixtures to make development testing easier --- db/fixtures/development/14_builds.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'db') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index e65abe4ef77..3734c861078 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -28,24 +28,44 @@ class Gitlab::Seeder::Builds build_create!(pipeline, name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :success) commit_status_create!(pipeline, name: 'jenkins', status: :success) - print '.' rescue ActiveRecord::RecordInvalid print 'F' + ensure + pipeline.build_updated end end end def pipelines - commits = @project.repository.commits('master', limit: 5) - commits_sha = commits.map { |commit| commit.raw.id } - commits_sha.map do |sha| - @project.ensure_pipeline(sha, 'master') - end + master_pipelines + merge_request_pipelines + end + + def master_pipelines + create_pipelines_for(@project, 'master') rescue [] end + def merge_request_pipelines + @project.merge_requests.last(5).map do |merge_request| + create_pipelines(merge_request.source_project, merge_request.source_branch, merge_request.commits.last(5)) + end.flatten + rescue + [] + end + + def create_pipelines_for(project, ref) + commits = project.repository.commits(ref, limit: 5) + create_pipelines(project, ref, commits) + end + + def create_pipelines(project, ref, commits) + commits.map do |commit| + project.pipelines.create(sha: commit.id, ref: ref) + end + end + def build_create!(pipeline, opts = {}) attributes = build_attributes_for(pipeline, opts) build = Ci::Build.create!(attributes) -- cgit v1.2.1 From fd09311da93070546c52e65c0c2af9b8566c56b5 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 17 Aug 2016 11:18:57 +0100 Subject: Update fixtures to add a created status to pipeline --- db/fixtures/development/14_builds.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'db') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 0d493fa1c3c..069d9dd6226 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,9 +1,8 @@ class Gitlab::Seeder::Builds - STAGES = %w[build notify_build test notify_test deploy notify_deploy] + STAGES = %w[build test deploy notify] BUILDS = [ { name: 'build:linux', stage: 'build', status: :success }, { name: 'build:osx', stage: 'build', status: :success }, - { name: 'slack post build', stage: 'notify_build', status: :success }, { name: 'rspec:linux', stage: 'test', status: :success }, { name: 'rspec:windows', stage: 'test', status: :success }, { name: 'rspec:windows', stage: 'test', status: :success }, @@ -12,9 +11,9 @@ class Gitlab::Seeder::Builds { name: 'spinach:osx', stage: 'test', status: :canceled }, { name: 'cucumber:linux', stage: 'test', status: :running }, { name: 'cucumber:osx', stage: 'test', status: :failed }, - { name: 'slack post test', stage: 'notify_test', status: :success }, { name: 'staging', stage: 'deploy', environment: 'staging', status: :success }, - { name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :success }, + { name: 'production', stage: 'deploy', environment: 'production', when: 'manual', status: :skipped }, + { name: 'slack', stage: 'notify', when: 'manual', status: :created }, ] def initialize(project) @@ -25,7 +24,7 @@ class Gitlab::Seeder::Builds pipelines.each do |pipeline| begin BUILDS.each { |opts| build_create!(pipeline, opts) } - commit_status_create!(pipeline, name: 'jenkins', status: :success) + commit_status_create!(pipeline, name: 'jenkins', stage: 'test', status: :success) print '.' rescue ActiveRecord::RecordInvalid print 'F' -- cgit v1.2.1 From 611dab2e522e5e59cf09cd459a31686e65616863 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 27 Jul 2016 16:32:32 -0300 Subject: Add Board model --- db/migrate/20160727191041_create_boards.rb | 13 +++++++++++++ db/migrate/20160727193336_create_lists.rb | 12 ++++++++++++ db/schema.rb | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 db/migrate/20160727191041_create_boards.rb create mode 100644 db/migrate/20160727193336_create_lists.rb (limited to 'db') diff --git a/db/migrate/20160727191041_create_boards.rb b/db/migrate/20160727191041_create_boards.rb new file mode 100644 index 00000000000..56afbd4e030 --- /dev/null +++ b/db/migrate/20160727191041_create_boards.rb @@ -0,0 +1,13 @@ +class CreateBoards < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :boards do |t| + t.references :project, index: true, foreign_key: true, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160727193336_create_lists.rb b/db/migrate/20160727193336_create_lists.rb new file mode 100644 index 00000000000..e962353986c --- /dev/null +++ b/db/migrate/20160727193336_create_lists.rb @@ -0,0 +1,12 @@ +class CreateLists < ActiveRecord::Migration + def change + create_table :lists do |t| + t.references :board, index: true, foreign_key: true, null: false + t.references :label, index: true, foreign_key: true + t.integer :list_type, null: false, default: 0 + t.integer :position, null: false + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 445f484a8c7..aec00136ff8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -117,6 +117,14 @@ ActiveRecord::Schema.define(version: 20160810142633) do add_index "award_emoji", ["user_id", "name"], name: "index_award_emoji_on_user_id_and_name", using: :btree add_index "award_emoji", ["user_id"], name: "index_award_emoji_on_user_id", using: :btree + create_table "boards", force: :cascade do |t| + t.integer "project_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "boards", ["project_id"], name: "index_boards_on_project_id", using: :btree + create_table "broadcast_messages", force: :cascade do |t| t.text "message", null: false t.datetime "starts_at" @@ -533,6 +541,18 @@ ActiveRecord::Schema.define(version: 20160810142633) do add_index "lfs_objects_projects", ["project_id"], name: "index_lfs_objects_projects_on_project_id", using: :btree + create_table "lists", force: :cascade do |t| + t.integer "board_id", null: false + t.integer "label_id" + t.integer "list_type", default: 0, null: false + t.integer "position", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "lists", ["board_id"], name: "index_lists_on_board_id", using: :btree + add_index "lists", ["label_id"], name: "index_lists_on_label_id", using: :btree + create_table "members", force: :cascade do |t| t.integer "access_level", null: false t.integer "source_id", null: false @@ -1116,6 +1136,9 @@ ActiveRecord::Schema.define(version: 20160810142633) do add_index "web_hooks", ["project_id"], name: "index_web_hooks_on_project_id", using: :btree + add_foreign_key "boards", "projects" + add_foreign_key "lists", "boards" + add_foreign_key "lists", "labels" add_foreign_key "personal_access_tokens", "users" add_foreign_key "protected_branch_merge_access_levels", "protected_branches" add_foreign_key "protected_branch_push_access_levels", "protected_branches" -- cgit v1.2.1 From 6e8d06a5949a32b52850ef6aecdd2231aaced01b Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 3 Aug 2016 13:08:58 -0300 Subject: fixup! Add List model --- db/migrate/20160727193336_create_lists.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'db') diff --git a/db/migrate/20160727193336_create_lists.rb b/db/migrate/20160727193336_create_lists.rb index e962353986c..12bb5605aad 100644 --- a/db/migrate/20160727193336_create_lists.rb +++ b/db/migrate/20160727193336_create_lists.rb @@ -1,4 +1,8 @@ class CreateLists < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + def change create_table :lists do |t| t.references :board, index: true, foreign_key: true, null: false -- cgit v1.2.1 From b07c5f23b8761ae87d29ded1a69b14ae6393443a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 28 Jul 2016 19:26:16 -0300 Subject: Order board lists by list_type, and position --- db/migrate/20160727193336_create_lists.rb | 4 ++-- db/schema.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'db') diff --git a/db/migrate/20160727193336_create_lists.rb b/db/migrate/20160727193336_create_lists.rb index 12bb5605aad..61d501215f2 100644 --- a/db/migrate/20160727193336_create_lists.rb +++ b/db/migrate/20160727193336_create_lists.rb @@ -7,8 +7,8 @@ class CreateLists < ActiveRecord::Migration create_table :lists do |t| t.references :board, index: true, foreign_key: true, null: false t.references :label, index: true, foreign_key: true - t.integer :list_type, null: false, default: 0 - t.integer :position, null: false + t.integer :list_type, null: false, default: 1 + t.integer :position t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index aec00136ff8..873dfa81702 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -544,8 +544,8 @@ ActiveRecord::Schema.define(version: 20160810142633) do create_table "lists", force: :cascade do |t| t.integer "board_id", null: false t.integer "label_id" - t.integer "list_type", default: 0, null: false - t.integer "position", null: false + t.integer "list_type", default: 1, null: false + t.integer "position" t.datetime "created_at", null: false t.datetime "updated_at", null: false end -- cgit v1.2.1 From c14ac835756d1d0f4d0f8279759e2b7f75364447 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 3 Aug 2016 14:21:22 -0300 Subject: Ensure that we have only one list per label per board --- .../20160803161903_add_unique_index_to_lists_label_id.rb | 15 +++++++++++++++ db/schema.rb | 1 + 2 files changed, 16 insertions(+) create mode 100644 db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb (limited to 'db') diff --git a/db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb b/db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb new file mode 100644 index 00000000000..baf2e70b127 --- /dev/null +++ b/db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb @@ -0,0 +1,15 @@ +class AddUniqueIndexToListsLabelId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :lists, [:board_id, :label_id], unique: true + end + + def down + remove_index :lists, column: [:board_id, :label_id] if index_exists?(:lists, [:board_id, :label_id], unique: true) + end +end diff --git a/db/schema.rb b/db/schema.rb index 873dfa81702..0cdcc080227 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -550,6 +550,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do t.datetime "updated_at", null: false end + add_index "lists", ["board_id", "label_id"], name: "index_lists_on_board_id_and_label_id", unique: true, using: :btree add_index "lists", ["board_id"], name: "index_lists_on_board_id", using: :btree add_index "lists", ["label_id"], name: "index_lists_on_label_id", using: :btree -- cgit v1.2.1