From 2a7a19c93ee0e0d77e4e388d43f36a721c7ab715 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 20 Oct 2023 21:27:06 -0400 Subject: Added post voting --- db/migrate/20231020194529_create_votes.rb | 11 +++++++++++ db/migrate/20231020195330_make_blog_votable.rb | 8 ++++++++ db/schema.rb | 14 +++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20231020194529_create_votes.rb create mode 100644 db/migrate/20231020195330_make_blog_votable.rb (limited to 'db') diff --git a/db/migrate/20231020194529_create_votes.rb b/db/migrate/20231020194529_create_votes.rb new file mode 100644 index 0000000..947652b --- /dev/null +++ b/db/migrate/20231020194529_create_votes.rb @@ -0,0 +1,11 @@ +class CreateVotes < ActiveRecord::Migration[7.0] + def change + create_table :votes do |t| + t.references :votable, polymorphic: true + t.integer :upvote + t.string :ip + + t.timestamps + end + end +end diff --git a/db/migrate/20231020195330_make_blog_votable.rb b/db/migrate/20231020195330_make_blog_votable.rb new file mode 100644 index 0000000..4d1e42a --- /dev/null +++ b/db/migrate/20231020195330_make_blog_votable.rb @@ -0,0 +1,8 @@ +class MakeBlogVotable < ActiveRecord::Migration[7.0] + def change + change_table :blogs do |t| + t.integer :upvotes, default: 0, null: false + t.integer :downvotes, default: 0, null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a9e111..f8a8c49 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[7.0].define(version: 2023_10_17_153558) do +ActiveRecord::Schema[7.0].define(version: 2023_10_20_195330) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -70,6 +70,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do t.boolean "published", default: false, null: false t.datetime "published_at", precision: nil t.integer "user_id" + t.integer "upvotes", default: 0, null: false + t.integer "downvotes", default: 0, null: false t.index ["user_id"], name: "index_blogs_on_user_id" end @@ -393,6 +395,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + create_table "votes", force: :cascade do |t| + t.string "votable_type" + t.integer "votable_id" + t.integer "upvote" + t.string "ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["votable_type", "votable_id"], name: "index_votes_on_votable" + end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "blogs", "users" -- cgit 1.4.1