Class: SlashMigrate::ColumnsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SlashMigrate::ColumnsController
- Defined in:
- app/controllers/slash_migrate/columns_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #drop ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #update ⇒ Object
- #update_preview ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 19 def create migration = AddColumnsMigration.from_params(table: @table, rows: params[:attributes]) unless migration.any? redirect_to(new_table_column_path(@table), alert: "Add at least one column.") return end written = migration.write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#drop ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 40 def drop column = find_column head :not_found and return unless column written = DropColumnMigration.new(table: @table, column: column).write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#edit ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 32 def edit @column = find_column head :not_found and return unless @column @drop_migration = DropColumnMigration.new(table: @table, column: @column) @drop_caveat = drop_caveat end |
#new ⇒ Object
5 6 7 8 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 5 def new @migration = AddColumnsMigration.new(table: @table) @existing_tables = inspector.table_names end |
#preview ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 10 def preview @migration = AddColumnsMigration.from_params(table: @table, rows: params[:attributes]) @hint = "Add a column to see the migration it will generate." unless @migration.any? render :preview, layout: false rescue => e @error = e. render :preview, layout: false end |
#update ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 59 def update original = find_column head :not_found and return unless original migration = EditColumnMigration.new(table: @table, original: original, desired: desired_column) unless migration.changed? redirect_to(edit_table_column_path(@table, params[:name]), alert: "No changes to apply.") return end written = migration.write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#update_preview ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/slash_migrate/columns_controller.rb', line 49 def update_preview original = find_column @migration = original && EditColumnMigration.new(table: @table, original: original, desired: desired_column) @hint = "Change a value to see the migration it will generate." unless @migration&.changed? render :update_preview, layout: false rescue => e @error = e. render :update_preview, layout: false end |