Feature: Access tokens for API access (#604)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
23
db/migrate/20200309170810_create_access_tokens.rb
Normal file
23
db/migrate/20200309170810_create_access_tokens.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateAccessTokens < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :access_tokens do |t|
|
||||
t.references :owner, polymorphic: true, index: true
|
||||
t.string :token, index: { unique: true }
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
remove_column :agent_bots, :auth_token, :string
|
||||
|
||||
[::User, ::AgentBot].each do |access_tokenable|
|
||||
generate_access_tokens(access_tokenable)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_access_tokens(access_tokenable)
|
||||
access_tokenable.find_in_batches do |record_batch|
|
||||
record_batch.each do |record|
|
||||
record.create_access_token if record.access_token.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class AddAccountIdToAgentBotInboxes < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :agent_bot_inboxes, :account_id, :integer, index: true
|
||||
|
||||
AgentBotInbox.all.each do |agent_bot_inbox|
|
||||
agent_bot_inbox.account_id = agent_bot_inbox.inbox.account_id
|
||||
agent_bot_inbox.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user