diff --git a/app/models/session.rb b/app/models/session.rb new file mode 100644 index 0000000..cf376fb --- /dev/null +++ b/app/models/session.rb @@ -0,0 +1,3 @@ +class Session < ApplicationRecord + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 39e0d66..591c68a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,4 +18,5 @@ class User < ApplicationRecord has_secure_password has_many :price_reports, dependent: :nullify has_many :moderation_logs, foreign_key: :admin_id, dependent: :nullify + has_many :sessions, dependent: :destroy end diff --git a/db/migrate/20260609155259_create_sessions.rb b/db/migrate/20260609155259_create_sessions.rb new file mode 100644 index 0000000..fb73005 --- /dev/null +++ b/db/migrate/20260609155259_create_sessions.rb @@ -0,0 +1,13 @@ +class CreateSessions < ActiveRecord::Migration[8.0] + def change + create_table :sessions do |t| + t.references :user, null: false, foreign_key: true + t.string :token + t.string :user_agent + t.string :ip_address + + t.timestamps + end + add_index :sessions, :token, unique: true + end +end diff --git a/db/migrate/20260609155729_remove_token_from_users.rb b/db/migrate/20260609155729_remove_token_from_users.rb new file mode 100644 index 0000000..b614365 --- /dev/null +++ b/db/migrate/20260609155729_remove_token_from_users.rb @@ -0,0 +1,5 @@ +class RemoveTokenFromUsers < ActiveRecord::Migration[8.0] + def change + remove_column :users, :token, :string + end +end diff --git a/test/fixtures/sessions.yml b/test/fixtures/sessions.yml new file mode 100644 index 0000000..2a4c855 --- /dev/null +++ b/test/fixtures/sessions.yml @@ -0,0 +1,13 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user: one + token: MyString + user_agent: MyString + ip_address: MyString + +two: + user: two + token: MyString + user_agent: MyString + ip_address: MyString diff --git a/test/models/session_test.rb b/test/models/session_test.rb new file mode 100644 index 0000000..47ad906 --- /dev/null +++ b/test/models/session_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class SessionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end