20190715164535_add_instance_actor.rb 770 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class AddInstanceActor < ActiveRecord::Migration[5.2]
  3. class Account < ApplicationRecord
  4. # Dummy class, to make migration possible across version changes
  5. validates :username, uniqueness: { scope: :domain, case_sensitive: false }
  6. INSTANCE_ACTOR_ID = -99
  7. before_create :generate_keys
  8. def generate_keys
  9. keypair = OpenSSL::PKey::RSA.new(2048)
  10. self.private_key = keypair.to_pem
  11. self.public_key = keypair.public_key.to_pem
  12. end
  13. end
  14. def up
  15. Account.create!(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
  16. end
  17. def down
  18. Account.find_by(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application').destroy!
  19. end
  20. end