Class: SlashMigrate::IndexesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SlashMigrate::IndexesController
- Defined in:
- app/controllers/slash_migrate/indexes_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/slash_migrate/indexes_controller.rb', line 19 def create migration = build_migration unless migration.any? redirect_to(new_table_index_path(@table), alert: "Pick at least one column to index.") return end written = migration.write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#drop ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/slash_migrate/indexes_controller.rb', line 31 def drop index = inspector.table(@table).indexes.find { |candidate| candidate.name == params[:name] } head :not_found and return unless index written = DropIndexMigration.new(table: @table, index: index).write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#new ⇒ Object
5 6 7 8 |
# File 'app/controllers/slash_migrate/indexes_controller.rb', line 5 def new @columns = inspector.table(@table).columns.map(&:name) @migration = AddIndexMigration.new(table: @table) end |
#preview ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/controllers/slash_migrate/indexes_controller.rb', line 10 def preview @migration = build_migration @hint = "Pick a column to index to see the migration it will generate." unless @migration.any? render_stream :preview rescue => e @error = e. render_stream :preview end |