auth: add sessions table
This commit is contained in:
parent
54bdd52e75
commit
1acd3e30ae
6 changed files with 42 additions and 0 deletions
3
app/models/session.rb
Normal file
3
app/models/session.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Session < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
end
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
13
db/migrate/20260609155259_create_sessions.rb
Normal file
13
db/migrate/20260609155259_create_sessions.rb
Normal 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
|
||||||
5
db/migrate/20260609155729_remove_token_from_users.rb
Normal file
5
db/migrate/20260609155729_remove_token_from_users.rb
Normal 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
13
test/fixtures/sessions.yml
vendored
Normal 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
|
||||||
7
test/models/session_test.rb
Normal file
7
test/models/session_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class SessionTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue