summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-10-05 16:41:32 +0200
committerRémy Coutable <remy@rymai.me>2017-04-14 15:20:55 +0200
commit2951a8543ef97ceb1bcaca5f5140d822729c950b (patch)
treeff02540e813cd93e8df8a438c9b22cdacc96982e /db
parentb61199ce0ccdfcd11a338778ce300cd15e5f2a43 (diff)
downloadgitlab-ce-2951a8543ef97ceb1bcaca5f5140d822729c950b.tar.gz
Add user activity service and spec. Also added relevant - NOT offline - migration
It uses a user activity table instead of a column in users. Tested with mySQL and postgreSQL
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20161007073613_create_user_activities.rb27
-rw-r--r--db/schema.rb8
2 files changed, 35 insertions, 0 deletions
diff --git a/db/migrate/20161007073613_create_user_activities.rb b/db/migrate/20161007073613_create_user_activities.rb
new file mode 100644
index 00000000000..4239cebd8f6
--- /dev/null
+++ b/db/migrate/20161007073613_create_user_activities.rb
@@ -0,0 +1,27 @@
+class CreateUserActivities < ActiveRecord::Migration
+ # 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 = 'Adding foreign key'
+
+ # 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
+ create_table :user_activities do |t|
+ t.belongs_to :user, index: { unique: true }, foreign_key: { on_delete: :cascade }
+ t.datetime :last_activity_at, null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1c592dd5d6d..3ed28a02de2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1230,6 +1230,13 @@ ActiveRecord::Schema.define(version: 20170408033905) do
add_index "uploads", ["model_id", "model_type"], name: "index_uploads_on_model_id_and_model_type", using: :btree
add_index "uploads", ["path"], name: "index_uploads_on_path", using: :btree
+ create_table "user_activities", force: :cascade do |t|
+ t.integer "user_id"
+ t.datetime "last_activity_at", null: false
+ end
+
+ add_index "user_activities", ["user_id"], name: "index_user_activities_on_user_id", unique: true, using: :btree
+
create_table "user_agent_details", force: :cascade do |t|
t.string "user_agent", null: false
t.string "ip_address", null: false
@@ -1389,4 +1396,5 @@ ActiveRecord::Schema.define(version: 20170408033905) do
add_foreign_key "timelogs", "merge_requests", name: "fk_timelogs_merge_requests_merge_request_id", on_delete: :cascade
add_foreign_key "trending_projects", "projects", on_delete: :cascade
add_foreign_key "u2f_registrations", "users"
+ add_foreign_key "user_activities", "users", on_delete: :cascade
end