From 544e9c8fa671c34c541aeb711d6f5e60b3be66f2 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 27 Jan 2022 22:42:01 +0100 Subject: [PATCH] Create Appendable model --- app/models/appendable.rb | 6 +++++ .../20220127212925_create_appendables.rb | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/models/appendable.rb create mode 100644 db/migrate/20220127212925_create_appendables.rb diff --git a/app/models/appendable.rb b/app/models/appendable.rb new file mode 100644 index 00000000..f736acfa --- /dev/null +++ b/app/models/appendable.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class Appendable < ApplicationRecord + belongs_to :parent, polymorphic: true + belongs_to :user +end diff --git a/db/migrate/20220127212925_create_appendables.rb b/db/migrate/20220127212925_create_appendables.rb new file mode 100644 index 00000000..8cf9830b --- /dev/null +++ b/db/migrate/20220127212925_create_appendables.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class CreateAppendables < ActiveRecord::Migration[6.1] + def up + create_table :appendables 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.timestamps + end + + change_column :appendables, :id, :bigint + add_index :appendables, %i[parent_id parent_type] + add_index :appendables, %i[user_id created_at] + end + + def down + drop_table :appendables + end +end