summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2018-08-26 11:24:55 +0200
committerGabriel Mazetto <brodock@gmail.com>2018-08-26 11:24:55 +0200
commit414c54cec2e6e3b9c6e4cf003b78a637464b6d8b (patch)
tree2ef19ba39527fc3d6ec1767c77716f2e13ca4de8 /db
parent2e719bda0aec3970bcda06a21aa1e5eb41db323b (diff)
downloadgitlab-ce-414c54cec2e6e3b9c6e4cf003b78a637464b6d8b.tar.gz
recalculate SiteStatistics
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180826111825_recalculate_site_statistics.rb27
-rw-r--r--db/schema.rb2
2 files changed, 28 insertions, 1 deletions
diff --git a/db/post_migrate/20180826111825_recalculate_site_statistics.rb b/db/post_migrate/20180826111825_recalculate_site_statistics.rb
new file mode 100644
index 00000000000..741035a444f
--- /dev/null
+++ b/db/post_migrate/20180826111825_recalculate_site_statistics.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class RecalculateSiteStatistics < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ transaction do
+ execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql? # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
+
+ execute("UPDATE site_statistics SET repositories_count = (SELECT COUNT(*) FROM projects)")
+ end
+
+ transaction do
+ execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql? # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
+
+ execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)")
+ end
+ end
+
+ def down
+ # No downside in keeping the counter up-to-date
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f5ce7df60e8..24f1fe71007 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: 20180816193530) do
+ActiveRecord::Schema.define(version: 20180826111825) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"