mirror of https://github.com/docusealco/docuseal
				
				
				
			
							parent
							
								
									e75e7b18b4
								
							
						
					
					
						commit
						6d78d5430c
					
				| @ -0,0 +1,39 @@ | |||||||
|  | # frozen_string_literal: true | ||||||
|  | 
 | ||||||
|  | # == Schema Information | ||||||
|  | # | ||||||
|  | # Table name: access_tokens | ||||||
|  | # | ||||||
|  | #  id         :bigint           not null, primary key | ||||||
|  | #  sha256     :text             not null | ||||||
|  | #  token      :text             not null | ||||||
|  | #  created_at :datetime         not null | ||||||
|  | #  updated_at :datetime         not null | ||||||
|  | #  user_id    :bigint           not null | ||||||
|  | # | ||||||
|  | # Indexes | ||||||
|  | # | ||||||
|  | #  index_access_tokens_on_sha256   (sha256) UNIQUE | ||||||
|  | #  index_access_tokens_on_user_id  (user_id) | ||||||
|  | # | ||||||
|  | # Foreign Keys | ||||||
|  | # | ||||||
|  | #  fk_rails_...  (user_id => users.id) | ||||||
|  | # | ||||||
|  | class AccessToken < ApplicationRecord | ||||||
|  |   TOKEN_LENGTH = 22 | ||||||
|  | 
 | ||||||
|  |   belongs_to :user | ||||||
|  | 
 | ||||||
|  |   before_validation :set_sha256, on: :create | ||||||
|  | 
 | ||||||
|  |   attribute :token, :string, default: -> { SecureRandom.base58(TOKEN_LENGTH) } | ||||||
|  | 
 | ||||||
|  |   encrypts :token | ||||||
|  | 
 | ||||||
|  |   private | ||||||
|  | 
 | ||||||
|  |   def set_sha256 | ||||||
|  |     self.sha256 = Digest::SHA256.hexdigest(token) | ||||||
|  |   end | ||||||
|  | end | ||||||
| @ -0,0 +1,13 @@ | |||||||
|  | # frozen_string_literal: true | ||||||
|  | 
 | ||||||
|  | class CreateAccessTokens < ActiveRecord::Migration[7.0] | ||||||
|  |   def change | ||||||
|  |     create_table :access_tokens do |t| | ||||||
|  |       t.references :user, null: false, foreign_key: true, index: true | ||||||
|  |       t.text :token, null: false | ||||||
|  |       t.text :sha256, null: false, index: { unique: true } | ||||||
|  | 
 | ||||||
|  |       t.timestamps | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
					Loading…
					
					
				
		Reference in new issue