add post
This commit is contained in:
11
db/migrate/20220227194054_create_posts.rb
Normal file
11
db/migrate/20220227194054_create_posts.rb
Normal 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
14
db/schema.rb
generated
@@ -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
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user