auth: add sessions table

This commit is contained in:
Mohammad Kanaan 2026-06-09 18:59:17 +03:00
parent 54bdd52e75
commit 1acd3e30ae
6 changed files with 42 additions and 0 deletions

3
app/models/session.rb Normal file
View file

@ -0,0 +1,3 @@
class Session < ApplicationRecord
belongs_to :user
end

View file

@ -18,4 +18,5 @@ class User < ApplicationRecord
has_secure_password has_secure_password
has_many :price_reports, dependent: :nullify has_many :price_reports, dependent: :nullify
has_many :moderation_logs, foreign_key: :admin_id, dependent: :nullify has_many :moderation_logs, foreign_key: :admin_id, dependent: :nullify
has_many :sessions, dependent: :destroy
end end

View file

@ -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

View file

@ -0,0 +1,5 @@
class RemoveTokenFromUsers < ActiveRecord::Migration[8.0]
def change
remove_column :users, :token, :string
end
end

13
test/fixtures/sessions.yml vendored Normal file
View file

@ -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

View file

@ -0,0 +1,7 @@
require "test_helper"
class SessionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end