about summary refs log tree commit diff stats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20231020194529_create_votes.rb11
-rw-r--r--db/migrate/20231020195330_make_blog_votable.rb8
-rw-r--r--db/schema.rb14
3 files changed, 32 insertions, 1 deletions
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 @@
1class CreateVotes < ActiveRecord::Migration[7.0]
2 def change
3 create_table :votes do |t|
4 t.references :votable, polymorphic: true
5 t.integer :upvote
6 t.string :ip
7
8 t.timestamps
9 end
10 end
11end
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 @@
1class MakeBlogVotable < ActiveRecord::Migration[7.0]
2 def change
3 change_table :blogs do |t|
4 t.integer :upvotes, default: 0, null: false
5 t.integer :downvotes, default: 0, null: false
6 end
7 end
8end
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 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do 13ActiveRecord::Schema[7.0].define(version: 2023_10_20_195330) do
14 create_table "active_storage_attachments", force: :cascade do |t| 14 create_table "active_storage_attachments", force: :cascade do |t|
15 t.string "name", null: false 15 t.string "name", null: false
16 t.string "record_type", null: false 16 t.string "record_type", null: false
@@ -70,6 +70,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do
70 t.boolean "published", default: false, null: false 70 t.boolean "published", default: false, null: false
71 t.datetime "published_at", precision: nil 71 t.datetime "published_at", precision: nil
72 t.integer "user_id" 72 t.integer "user_id"
73 t.integer "upvotes", default: 0, null: false
74 t.integer "downvotes", default: 0, null: false
73 t.index ["user_id"], name: "index_blogs_on_user_id" 75 t.index ["user_id"], name: "index_blogs_on_user_id"
74 end 76 end
75 77
@@ -393,6 +395,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do
393 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 395 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
394 end 396 end
395 397
398 create_table "votes", force: :cascade do |t|
399 t.string "votable_type"
400 t.integer "votable_id"
401 t.integer "upvote"
402 t.string "ip"
403 t.datetime "created_at", null: false
404 t.datetime "updated_at", null: false
405 t.index ["votable_type", "votable_id"], name: "index_votes_on_votable"
406 end
407
396 add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" 408 add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
397 add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" 409 add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
398 add_foreign_key "blogs", "users" 410 add_foreign_key "blogs", "users"