Class: Migflow::Api::MigrationsController

Inherits:
Migflow::ApplicationController show all
Defined in:
app/controllers/migflow/api/migrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
9
# File 'app/controllers/migflow/api/migrations_controller.rb', line 6

def index
  migrations = Parsers::MigrationParser.call(migrations_path: migrations_path)
  render_json(migrations: migrations.map { |m| serialize_summary(m, migrations) })
end

#showObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/migflow/api/migrations_controller.rb', line 11

def show
  migrations = Parsers::MigrationParser.call(migrations_path: migrations_path)
  migration  = migrations.find { |m| m[:version] == params[:id] }

  return render_error("Migration not found", status: :not_found) unless migration

  result   = Services::SnapshotBuilder.call(migrations: migrations, up_to_version: params[:id])
  snapshot = snapshot_model_from(result[:schema_after], migration[:version])
  warnings = Services::ScopedMigrationWarnings.call(snapshot: snapshot, migration: migration, diff: result[:diff])
  risk     = Services::RiskScorer.new.call(warnings)

  render_json(migration: serialize_detail(migration, result, warnings, risk))
end