Add slack neighborhood channel into db

This commit is contained in:
Max Wofford
2025-05-06 12:23:30 -04:00
parent 0fa7394162
commit f45a555b5d
4 changed files with 23 additions and 1 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -0,0 +1,5 @@
class AddSlackNeighborhoodChannelToUsers < ActiveRecord::Migration[8.0]
def change
add_column :users, :slack_neighborhood_channel, :string, null: true
end
end

3
db/schema.rb generated
View File

@@ -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