2022-09-11 11:10:01 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "webpush"
|
|
|
|
|
|
|
|
class AddWebpushApp < ActiveRecord::Migration[6.1]
|
|
|
|
def up
|
|
|
|
vapid_keypair = Webpush.generate_key.to_hash
|
|
|
|
app = Rpush::Webpush::App.new
|
|
|
|
app.name = "webpush"
|
2022-12-26 03:03:18 -08:00
|
|
|
app.certificate = vapid_keypair.merge(subject: APP_CONFIG.fetch("contact_email")).to_json
|
2022-09-11 11:10:01 -07:00
|
|
|
app.connections = 1
|
|
|
|
app.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
Rpush::Webpush::App.find_by(name: "webpush").destroy!
|
|
|
|
end
|
|
|
|
end
|