From 4e08f035d1b1f5fd9577fb8e4469bfc8ab194137 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 11 Sep 2022 20:10:01 +0200 Subject: [PATCH] Create migration for adding an rpush app for webpush --- db/migrate/20220909220449_add_webpush_app.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/migrate/20220909220449_add_webpush_app.rb diff --git a/db/migrate/20220909220449_add_webpush_app.rb b/db/migrate/20220909220449_add_webpush_app.rb new file mode 100644 index 00000000..e527d64c --- /dev/null +++ b/db/migrate/20220909220449_add_webpush_app.rb @@ -0,0 +1,18 @@ +# 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" + app.certificate = vapid_keypair.merge(subject: "user@example.com").to_json # TODO: put an email address here + app.connections = 1 + app.save! + end + + def down + Rpush::Webpush::App.find_by(name: "webpush").destroy! + end +end