diff --git a/Gemfile b/Gemfile index ced71558..08ae4bf0 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,8 @@ gem "flamegraph" gem "skylight" +gem "public_activity" + # Ahoy analytics gem "ahoy_matey" gem "geocoder" diff --git a/Gemfile.lock b/Gemfile.lock index 7c9f48b5..144e3025 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -334,6 +334,11 @@ GEM psych (5.2.4) date stringio + public_activity (3.0.1) + actionpack (>= 6.1.0) + activerecord (>= 6.1) + i18n (>= 0.5.0) + railties (>= 6.1.0) public_suffix (6.0.2) puma (6.6.0) nio4r (~> 2.0) @@ -549,6 +554,7 @@ DEPENDENCIES paper_trail pg propshaft + public_activity puma (>= 5.0) query_count rack-cors diff --git a/app/models/project_repo_mapping.rb b/app/models/project_repo_mapping.rb index 7fd09800..cb40bd94 100644 --- a/app/models/project_repo_mapping.rb +++ b/app/models/project_repo_mapping.rb @@ -1,6 +1,9 @@ class ProjectRepoMapping < ApplicationRecord belongs_to :user + include PublicActivity::Model + tracked + after_save :invalidate_cache validates :project_name, presence: true diff --git a/db/migrate/20250507161052_create_activities.rb b/db/migrate/20250507161052_create_activities.rb new file mode 100644 index 00000000..eb129064 --- /dev/null +++ b/db/migrate/20250507161052_create_activities.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Migration responsible for creating a table with activities +class CreateActivities < ActiveRecord::Migration[6.1] + def self.up + create_table :activities do |t| + t.belongs_to :trackable, polymorphic: true + t.belongs_to :owner, polymorphic: true + t.string :key + t.text :parameters + t.belongs_to :recipient, polymorphic: true + + t.timestamps + end + + add_index :activities, %i[trackable_id trackable_type] + add_index :activities, %i[owner_id owner_type] + add_index :activities, %i[recipient_id recipient_type] + end + + # Drop table + def self.down + drop_table :activities + end +end diff --git a/db/schema.rb b/db/schema.rb index 81ade031..94cd1fc4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,10 +10,29 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_05_06_155521) do +ActiveRecord::Schema[8.0].define(version: 2025_05_07_161052) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" + create_table "activities", force: :cascade do |t| + t.string "trackable_type" + t.bigint "trackable_id" + t.string "owner_type" + t.bigint "owner_id" + t.string "key" + t.text "parameters" + t.string "recipient_type" + t.bigint "recipient_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["owner_id", "owner_type"], name: "index_activities_on_owner_id_and_owner_type" + t.index ["owner_type", "owner_id"], name: "index_activities_on_owner" + t.index ["recipient_id", "recipient_type"], name: "index_activities_on_recipient_id_and_recipient_type" + t.index ["recipient_type", "recipient_id"], name: "index_activities_on_recipient" + t.index ["trackable_id", "trackable_type"], name: "index_activities_on_trackable_id_and_trackable_type" + t.index ["trackable_type", "trackable_id"], name: "index_activities_on_trackable" + end + create_table "ahoy_events", force: :cascade do |t| t.bigint "visit_id" t.bigint "user_id"