This commit is contained in:
João Victor Geonizeli
2022-02-27 17:02:37 -03:00
parent 53c7d35d74
commit 1d692b31f8
13 changed files with 258 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
class CreatePosts < ActiveRecord::Migration[7.0]
def change
create_table :posts do |t|
t.text :content, null: true
t.references :user, null: false, references: :user, foreign_key: { to_table: :users }
t.references :quoted_post, null: true, references: :post, foreign_key: { to_table: :posts }
t.timestamps
end
end
end

14
db/schema.rb generated
View File

@@ -10,10 +10,20 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_02_27_175028) do
ActiveRecord::Schema[7.0].define(version: 2022_02_27_194054) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "posts", force: :cascade do |t|
t.text "content"
t.bigint "user_id", null: false
t.bigint "quoted_post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["quoted_post_id"], name: "index_posts_on_quoted_post_id"
t.index ["user_id"], name: "index_posts_on_user_id"
end
create_table "user_follows", force: :cascade do |t|
t.bigint "follower_id"
t.bigint "followed_id"
@@ -30,6 +40,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_02_27_175028) do
t.index ["username"], name: "index_users_on_username"
end
add_foreign_key "posts", "posts", column: "quoted_post_id"
add_foreign_key "posts", "users"
add_foreign_key "user_follows", "users", column: "followed_id"
add_foreign_key "user_follows", "users", column: "follower_id"
end

View File

@@ -4,3 +4,6 @@ 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)
first_post = Post.find_or_create_by(content: 'Hello World!', user_id: xpto.id)
Post.find_or_create_by(content: 'Hello World!', user_id: xpto.id, quoted_post_id: first_post.id)