20190715164535_add_instance_actor.rb 695 B

123456789101112131415161718192021222324
  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. before_create :generate_keys
  7. def generate_keys
  8. keypair = OpenSSL::PKey::RSA.new(2048)
  9. self.private_key = keypair.to_pem
  10. self.public_key = keypair.public_key.to_pem
  11. end
  12. end
  13. def up
  14. Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
  15. end
  16. def down
  17. Account.find_by(id: -99, actor_type: 'Application').destroy!
  18. end
  19. end