smellman's Broken Diary

クソみたいなもんです

2023/09/12の日記

生活と仕事

今日は朝ダウンしてしまって12:30に起きてすぐミーティングに参加。

13:00から仕事を開始。すぐミーティングがあって、英語で一時間ぐらいやりとりしていた。疲れた。

仕事をボチボチと進めていたけど、なかなか進まず。というか、昨日からやってるUUIDの件が大変だった。

夕方から半沢直樹を見ながら仕事をしていた。

結局UUIDの件は次のような修正をして上手くいった。

# frozen_string_literal: true

# change uuid to active storage
class ChangeUuidToActiveStorage < ActiveRecord::Migration[7.0]
  def up
    ActiveRecord::Base.connection.execute('DELETE FROM active_storage_attachments;')
    remove_index :active_storage_attachments, name: :index_active_storage_attachments_uniqueness, unique: true
    change_column_null :active_storage_attachments, :record_id, true, 0
    remove_column :active_storage_attachments, :record_id, :bigint, null: true
    add_column :active_storage_attachments, :record_id, :uuid, null: false, default: ''
    add_index :active_storage_attachments, %i[record_type record_id name blob_id],
              name: :index_active_storage_attachments_uniqueness, unique: true
  end

  def dow
    ActiveRecord::Base.connection.execute('DELETE FROM active_storage_attachments;')
    remove_index :active_storage_attachments, name: :index_active_storage_attachments_uniqueness, unique: true
    change_column_null :active_storage_attachments, :record_id, true, ''
    remove_column :active_storage_attachments, :record_id, :uuid, null: false
    add_column :active_storage_attachments, :record_id, :bigint, null: false, default: 0
    add_index :active_storage_attachments, %i[record_type record_id name blob_id],
              name: :index_active_storage_attachments_uniqueness, unique: true
  end
end

一旦active_storage_attachmentsを削除する必要があった。しかし、解決するまでめっちゃ時間かかって厳しかった。

今日はこんなところで。