Files
turbovault-app/db/migrate/20260328183451_create_collections.rb
2026-03-29 02:37:49 -04:00

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