Scaffold models
parent
5fd3cd3469
commit
11d208ef56
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Conversation < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
has_many :messages, dependent: :destro
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Message < ApplicationRecord
|
||||||
|
belongs_to :conversation
|
||||||
|
end
|
||||||
|
|
@ -4,4 +4,6 @@ class User < ApplicationRecord
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
|
||||||
validates :email, presence: true, uniqueness: true
|
validates :email, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
has_many :conversations, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateConversations < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
create_table :conversations do |t|
|
||||||
|
t.references :user, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateMessages < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
create_table :messages do |t|
|
||||||
|
t.text :body
|
||||||
|
t.boolean :reply, null: false, default: false
|
||||||
|
t.references :conversation, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,23 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_02_24_102503) do
|
ActiveRecord::Schema[8.0].define(version: 2025_03_01_202033) do
|
||||||
|
create_table "conversations", force: :cascade do |t|
|
||||||
|
t.integer "user_id", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["user_id"], name: "index_conversations_on_user_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "messages", force: :cascade do |t|
|
||||||
|
t.text "body"
|
||||||
|
t.boolean "reply", default: false, null: false
|
||||||
|
t.integer "conversation_id", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["conversation_id"], name: "index_messages_on_conversation_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", null: false
|
t.string "email", null: false
|
||||||
t.string "password_digest", null: false
|
t.string "password_digest", null: false
|
||||||
|
|
@ -18,4 +34,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_24_102503) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["email"], name: "index_users_on_email", unique: true
|
t.index ["email"], name: "index_users_on_email", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "conversations", "users"
|
||||||
|
add_foreign_key "messages", "conversations"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue