mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
Changes to Activity model
This commit is contained in:
parent
0bf7cb4c59
commit
5b5c6c7122
4 changed files with 38 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
class Activity < ApplicationRecord
|
class Activity < ApplicationRecord
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
|
|
||||||
after_create :generate_notification
|
# after_create :generate_notification
|
||||||
|
|
||||||
enum type_of: [
|
enum type_of: [
|
||||||
:create_project,
|
:create_project,
|
||||||
|
|
@ -66,9 +66,16 @@ class Activity < ApplicationRecord
|
||||||
validates :type_of, presence: true
|
validates :type_of, presence: true
|
||||||
|
|
||||||
belongs_to :project, inverse_of: :activities
|
belongs_to :project, inverse_of: :activities
|
||||||
|
|
||||||
|
# Depricated in SCI-3025
|
||||||
belongs_to :experiment, inverse_of: :activities, optional: true
|
belongs_to :experiment, inverse_of: :activities, optional: true
|
||||||
|
# Depricated in SCI-3025
|
||||||
belongs_to :my_module, inverse_of: :activities, optional: true
|
belongs_to :my_module, inverse_of: :activities, optional: true
|
||||||
belongs_to :user, inverse_of: :activities
|
belongs_to :owner, inverse_of: :activities, class_name: 'User'
|
||||||
|
|
||||||
|
# [MyModule, Experiment, Protoco...? Are we going to list all avaible types?]
|
||||||
|
belongs_to :subject, polymorphic: true
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
||||||
13
db/migrate/20190213064847_change_table_activities.rb
Normal file
13
db/migrate/20190213064847_change_table_activities.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ChangeTableActivities < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
add_reference :activities, :subject, polymorphic: true, index: true
|
||||||
|
add_reference :activities, :team, index: true
|
||||||
|
add_column :activities, :group_type, :integer
|
||||||
|
rename_column :activities, :user_id, :owner_id
|
||||||
|
add_column :activities, :values, :json
|
||||||
|
change_column_null :activities, :type_of, :integer, true
|
||||||
|
change_column_null :activities, :message, :string, true
|
||||||
|
end
|
||||||
|
end
|
||||||
20
db/schema.rb
20
db/schema.rb
|
|
@ -10,7 +10,8 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20190125123107) do
|
|
||||||
|
ActiveRecord::Schema.define(version: 20190213064847) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
@ -19,19 +20,26 @@ ActiveRecord::Schema.define(version: 20190125123107) do
|
||||||
|
|
||||||
create_table "activities", force: :cascade do |t|
|
create_table "activities", force: :cascade do |t|
|
||||||
t.bigint "my_module_id"
|
t.bigint "my_module_id"
|
||||||
t.bigint "user_id"
|
t.bigint "owner_id"
|
||||||
t.integer "type_of", null: false
|
t.integer "type_of"
|
||||||
t.string "message", null: false
|
t.string "message"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.bigint "project_id", null: false
|
t.bigint "project_id", null: false
|
||||||
t.bigint "experiment_id"
|
t.bigint "experiment_id"
|
||||||
|
t.string "subject_type"
|
||||||
|
t.bigint "subject_id"
|
||||||
|
t.bigint "team_id"
|
||||||
|
t.integer "group_type"
|
||||||
|
t.json "values"
|
||||||
t.index ["created_at"], name: "index_activities_on_created_at"
|
t.index ["created_at"], name: "index_activities_on_created_at"
|
||||||
t.index ["experiment_id"], name: "index_activities_on_experiment_id"
|
t.index ["experiment_id"], name: "index_activities_on_experiment_id"
|
||||||
t.index ["my_module_id"], name: "index_activities_on_my_module_id"
|
t.index ["my_module_id"], name: "index_activities_on_my_module_id"
|
||||||
|
t.index ["owner_id"], name: "index_activities_on_owner_id"
|
||||||
t.index ["project_id"], name: "index_activities_on_project_id"
|
t.index ["project_id"], name: "index_activities_on_project_id"
|
||||||
|
t.index ["subject_type", "subject_id"], name: "index_activities_on_subject_type_and_subject_id"
|
||||||
|
t.index ["team_id"], name: "index_activities_on_team_id"
|
||||||
t.index ["type_of"], name: "index_activities_on_type_of"
|
t.index ["type_of"], name: "index_activities_on_type_of"
|
||||||
t.index ["user_id"], name: "index_activities_on_user_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "asset_text_data", force: :cascade do |t|
|
create_table "asset_text_data", force: :cascade do |t|
|
||||||
|
|
@ -916,7 +924,7 @@ ActiveRecord::Schema.define(version: 20190125123107) do
|
||||||
add_foreign_key "activities", "experiments"
|
add_foreign_key "activities", "experiments"
|
||||||
add_foreign_key "activities", "my_modules"
|
add_foreign_key "activities", "my_modules"
|
||||||
add_foreign_key "activities", "projects"
|
add_foreign_key "activities", "projects"
|
||||||
add_foreign_key "activities", "users"
|
add_foreign_key "activities", "users", column: "owner_id"
|
||||||
add_foreign_key "asset_text_data", "assets"
|
add_foreign_key "asset_text_data", "assets"
|
||||||
add_foreign_key "assets", "users", column: "created_by_id"
|
add_foreign_key "assets", "users", column: "created_by_id"
|
||||||
add_foreign_key "assets", "users", column: "last_modified_by_id"
|
add_foreign_key "assets", "users", column: "last_modified_by_id"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ describe Activity, type: :model do
|
||||||
describe 'Database table' do
|
describe 'Database table' do
|
||||||
it { should have_db_column :id }
|
it { should have_db_column :id }
|
||||||
it { should have_db_column :my_module_id }
|
it { should have_db_column :my_module_id }
|
||||||
it { should have_db_column :user_id }
|
it { should have_db_column :owner_id }
|
||||||
it { should have_db_column :type_of }
|
it { should have_db_column :type_of }
|
||||||
it { should have_db_column :message }
|
it { should have_db_column :message }
|
||||||
it { should have_db_column :created_at }
|
it { should have_db_column :created_at }
|
||||||
|
|
@ -21,7 +21,7 @@ describe Activity, type: :model do
|
||||||
it { should belong_to :project }
|
it { should belong_to :project }
|
||||||
it { should belong_to :experiment }
|
it { should belong_to :experiment }
|
||||||
it { should belong_to :my_module }
|
it { should belong_to :my_module }
|
||||||
it { should belong_to :user }
|
it { should belong_to :owner }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Should be a valid object' do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue