mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 22:12:53 +00:00
23 lines
633 B
Ruby
23 lines
633 B
Ruby
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
|