class CreatePermissions < ActiveRecord::Migration[5.2] def up if !table_exists?(:permissions) create_table(:permissions) do |t| t.belongs_to :resource, polymorphic: true t.integer Recurso.identity_foreign_key t.integer :level, default: 0 t.timestamps end add_index :permissions, [:user_id] add_index :permissions, [:resource_type, :resource_id] add_index :permissions, [:user_id, :resource_type, :resource_id] end end end