2023-07-12 03:47:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-18 19:44:42 -04:00
|
|
|
class AddInstanceActor < ActiveRecord::Migration[5.2]
|
2022-01-30 15:38:54 -05:00
|
|
|
class Account < ApplicationRecord
|
|
|
|
# Dummy class, to make migration possible across version changes
|
|
|
|
validates :username, uniqueness: { scope: :domain, case_sensitive: false }
|
2022-04-26 15:22:09 -04:00
|
|
|
|
2024-02-19 06:09:43 -05:00
|
|
|
INSTANCE_ACTOR_ID = -99
|
|
|
|
|
2022-04-26 15:22:09 -04:00
|
|
|
before_create :generate_keys
|
|
|
|
|
|
|
|
def generate_keys
|
|
|
|
keypair = OpenSSL::PKey::RSA.new(2048)
|
|
|
|
self.private_key = keypair.to_pem
|
|
|
|
self.public_key = keypair.public_key.to_pem
|
|
|
|
end
|
2022-01-30 15:38:54 -05:00
|
|
|
end
|
|
|
|
|
2019-07-18 19:44:42 -04:00
|
|
|
def up
|
2024-02-19 06:09:43 -05:00
|
|
|
Account.create!(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
|
2019-07-18 19:44:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2024-02-19 06:09:43 -05:00
|
|
|
Account.find_by(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application').destroy!
|
2019-07-18 19:44:42 -04:00
|
|
|
end
|
|
|
|
end
|