add user follow feature

This commit is contained in:
João Victor Geonizeli
2022-02-27 16:13:52 -03:00
parent 011a8cdb77
commit 70e25e8399
15 changed files with 181 additions and 7 deletions

View File

@@ -0,0 +1,10 @@
class CreateUserFollows < ActiveRecord::Migration[7.0]
def change
create_table :user_follows do |t|
t.references :follower, references: :users, foreign_key: { to_table: :users }
t.references :followed, references: :users, foreign_key: { to_table: :users }
t.timestamps
end
end
end

13
db/schema.rb generated
View File

@@ -10,10 +10,19 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_02_27_172543) do
ActiveRecord::Schema[7.0].define(version: 2022_02_27_175028) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "user_follows", force: :cascade do |t|
t.bigint "follower_id"
t.bigint "followed_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["followed_id"], name: "index_user_follows_on_followed_id"
t.index ["follower_id"], name: "index_user_follows_on_follower_id"
end
create_table "users", force: :cascade do |t|
t.string "username", limit: 14, null: false
t.datetime "created_at", null: false
@@ -21,4 +30,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_02_27_172543) do
t.index ["username"], name: "index_users_on_username"
end
add_foreign_key "user_follows", "users", column: "followed_id"
add_foreign_key "user_follows", "users", column: "follower_id"
end

View File

@@ -1,3 +1,6 @@
User.find_or_create_by(username: 'xpto')
User.find_or_create_by(username: 'admin')
User.find_or_create_by(username: 'geonizeli')
xpto = User.find_or_create_by(username: 'xpto')
geonizeli = User.find_or_create_by(username: 'geonizeli')
UserFollow.find_or_create_by(follower_id: xpto.id, followed_id: geonizeli.id)
UserFollow.find_or_create_by(follower_id: geonizeli.id, followed_id: xpto.id)