diff --git a/app/models/user.rb b/app/models/user.rb index 3ec6b9c7..4b97f7d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,6 +42,7 @@ class User < ApplicationRecord has_many :subscriptions, dependent: :destroy_async has_many :totp_recovery_codes, dependent: :destroy_async + has_many :web_push_subscriptions, dependent: :destroy_async has_one :profile, dependent: :destroy has_one :theme, dependent: :destroy diff --git a/app/models/web_push_subscription.rb b/app/models/web_push_subscription.rb new file mode 100644 index 00000000..dddf28db --- /dev/null +++ b/app/models/web_push_subscription.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class WebPushSubscription < ApplicationRecord + belongs_to :user +end diff --git a/db/migrate/20220910000514_create_web_push_subscriptions.rb b/db/migrate/20220910000514_create_web_push_subscriptions.rb new file mode 100644 index 00000000..45a2dcf4 --- /dev/null +++ b/db/migrate/20220910000514_create_web_push_subscriptions.rb @@ -0,0 +1,11 @@ +class CreateWebPushSubscriptions < ActiveRecord::Migration[6.1] + def change + create_table :web_push_subscriptions do |t| + t.bigint :user_id, null: false + t.json :subscription + t.timestamps + end + + add_index :web_push_subscriptions, :user_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d453624..6c2491d6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -382,5 +382,13 @@ ActiveRecord::Schema.define(version: 2022_12_27_065923) do t.index ["user_id"], name: "index_users_roles_on_user_id" end + create_table "web_push_subscriptions", force: :cascade do |t| + t.bigint "user_id", null: false + t.json "subscription" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["user_id"], name: "index_web_push_subscriptions_on_user_id" + end + add_foreign_key "profiles", "users" end