From f45a555b5d8a002782b93a6b4e56a0cb17c18e79 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 6 May 2025 12:23:30 -0400 Subject: [PATCH] Add slack neighborhood channel into db --- app/jobs/one_time/set_neighborhood_channels_job.rb | 10 ++++++++++ app/models/user.rb | 6 ++++++ ...06155521_add_slack_neighborhood_channel_to_users.rb | 5 +++++ db/schema.rb | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/jobs/one_time/set_neighborhood_channels_job.rb create mode 100644 db/migrate/20250506155521_add_slack_neighborhood_channel_to_users.rb diff --git a/app/jobs/one_time/set_neighborhood_channels_job.rb b/app/jobs/one_time/set_neighborhood_channels_job.rb new file mode 100644 index 0000000..a148b57 --- /dev/null +++ b/app/jobs/one_time/set_neighborhood_channels_job.rb @@ -0,0 +1,10 @@ +class OneTime::SetNeighborhoodChannelsJob < ApplicationJob + queue_as :default + + def perform + User.where.not(slack_uid: nil).find_each(batch_size: 100) do |user| + user.set_neighborhood_channel + user.save! if user.changed? + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 0a04624..ede7fd8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,12 @@ class User < ApplicationRecord ).order(created_at: :desc).limit(10).all end + def set_neighborhood_channel + return unless slack_uid.present? + + self.slack_neighborhood_channel = SlackNeighborhood.find_by_id(slack_uid) + end + def format_extension_text(duration) case hackatime_extension_text_type when "simple_text" diff --git a/db/migrate/20250506155521_add_slack_neighborhood_channel_to_users.rb b/db/migrate/20250506155521_add_slack_neighborhood_channel_to_users.rb new file mode 100644 index 0000000..0f7435c --- /dev/null +++ b/db/migrate/20250506155521_add_slack_neighborhood_channel_to_users.rb @@ -0,0 +1,5 @@ +class AddSlackNeighborhoodChannelToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :slack_neighborhood_channel, :string, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index bfc57c9..81ade03 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_05_05_152654) do +ActiveRecord::Schema[8.0].define(version: 2025_05_06_155521) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -307,6 +307,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_05_152654) do t.text "github_access_token" t.string "github_username" t.string "slack_username" + t.string "slack_neighborhood_channel" t.index ["slack_uid"], name: "index_users_on_slack_uid", unique: true t.index ["timezone"], name: "index_users_on_timezone" end