From 1e6243c6ced64a863f6b8a652e43c29c644f5835 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 14 Jun 2022 17:09:10 +0200 Subject: [PATCH] Create AnonymousBlock model --- app/models/anonymous_block.rb | 4 +++ app/models/user.rb | 1 + .../20220614141439_create_anonymous_blocks.rb | 11 ++++++++ db/schema.rb | 27 ++++++++++--------- 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 app/models/anonymous_block.rb create mode 100644 db/migrate/20220614141439_create_anonymous_blocks.rb diff --git a/app/models/anonymous_block.rb b/app/models/anonymous_block.rb new file mode 100644 index 00000000..00327887 --- /dev/null +++ b/app/models/anonymous_block.rb @@ -0,0 +1,4 @@ +class AnonymousBlock < ApplicationRecord + belongs_to :user + belongs_to :question, optional: true +end diff --git a/app/models/user.rb b/app/models/user.rb index d93d4fb9..751f7c9e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,6 +37,7 @@ class User < ApplicationRecord has_many :lists, dependent: :destroy has_many :list_memberships, class_name: "ListMember", foreign_key: 'user_id', dependent: :destroy has_many :mute_rules, dependent: :destroy + has_many :anonymous_blocks, dependent: :destroy has_many :subscriptions, dependent: :destroy has_many :totp_recovery_codes, dependent: :destroy diff --git a/db/migrate/20220614141439_create_anonymous_blocks.rb b/db/migrate/20220614141439_create_anonymous_blocks.rb new file mode 100644 index 00000000..a9405039 --- /dev/null +++ b/db/migrate/20220614141439_create_anonymous_blocks.rb @@ -0,0 +1,11 @@ +class CreateAnonymousBlocks < ActiveRecord::Migration[6.1] + def change + create_table :anonymous_blocks do |t| + t.references :user, null: false, foreign_key: true + t.string :identifier, index: true + t.references :question, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 15457d1c..2fc1be5b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_06_13_221551) do +ActiveRecord::Schema.define(version: 2022_06_14_141439) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -27,6 +27,17 @@ ActiveRecord::Schema.define(version: 2022_06_13_221551) do t.index ["user_id"], name: "index_announcements_on_user_id" end + create_table "anonymous_blocks", force: :cascade do |t| + t.bigint "user_id", null: false + t.string "identifier" + t.bigint "question_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["identifier"], name: "index_anonymous_blocks_on_identifier" + t.index ["question_id"], name: "index_anonymous_blocks_on_question_id" + t.index ["user_id"], name: "index_anonymous_blocks_on_user_id" + end + create_table "answers", id: :bigint, default: -> { "gen_timestamp_id('answers'::text)" }, force: :cascade do |t| t.text "content" t.bigint "question_id" @@ -39,18 +50,6 @@ ActiveRecord::Schema.define(version: 2022_06_13_221551) do t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at" end - create_table "appendables", force: :cascade do |t| - t.string "type", null: false - t.bigint "user_id", null: false - t.bigint "parent_id", null: false - t.string "parent_type", null: false - t.text "content" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["parent_id", "parent_type"], name: "index_appendables_on_parent_id_and_parent_type" - t.index ["user_id", "created_at"], name: "index_appendables_on_user_id_and_created_at" - end - create_table "comment_smiles", id: :bigint, default: -> { "gen_timestamp_id('comment_smiles'::text)" }, force: :cascade do |t| t.bigint "user_id" t.bigint "comment_id" @@ -336,6 +335,8 @@ ActiveRecord::Schema.define(version: 2022_06_13_221551) do t.index ["user_id"], name: "index_users_roles_on_user_id" end + add_foreign_key "anonymous_blocks", "questions" + add_foreign_key "anonymous_blocks", "users" add_foreign_key "mute_rules", "users" add_foreign_key "profiles", "users" end