20190715164535_add_instance_actor.rb 664 B

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