mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 02:52:55 +00:00
Moving to github
This commit is contained in:
22
db/migrate/20260328183438_create_api_tokens.rb
Normal file
22
db/migrate/20260328183438_create_api_tokens.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class CreateApiTokens < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :api_tokens do |t|
|
||||
t.references :user, null: false, foreign_key: true, index: true
|
||||
t.string :token, null: false
|
||||
t.string :name
|
||||
t.datetime :last_used_at
|
||||
t.datetime :expires_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :api_tokens, :token, unique: true
|
||||
|
||||
# Enable Row Level Security
|
||||
execute <<-SQL
|
||||
ALTER TABLE api_tokens ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY api_tokens_isolation_policy ON api_tokens
|
||||
USING (user_id = current_setting('app.current_user_id', true)::bigint);
|
||||
SQL
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user