mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 21:02:52 +00:00
24 lines
702 B
Ruby
24 lines
702 B
Ruby
class CreateCollections < ActiveRecord::Migration[8.1]
|
|
def change
|
|
create_table :collections do |t|
|
|
t.references :user, null: false, foreign_key: true, index: true
|
|
t.string :name, null: false
|
|
t.text :description
|
|
t.integer :parent_collection_id
|
|
|
|
t.timestamps
|
|
end
|
|
|
|
add_index :collections, :parent_collection_id
|
|
add_foreign_key :collections, :collections, column: :parent_collection_id
|
|
|
|
# Enable Row Level Security
|
|
execute <<-SQL
|
|
ALTER TABLE collections ENABLE ROW LEVEL SECURITY;
|
|
|
|
CREATE POLICY collections_isolation_policy ON collections
|
|
USING (user_id = current_setting('app.current_user_id', true)::bigint);
|
|
SQL
|
|
end
|
|
end
|