class Frontline::Models

Public Instance Methods

delete_migration(model) click to toggle source

return a command that will delete the given migration of given model. `@name` variable are set by the triggered hooks(see frontline/app.rb for hooks)

# File lib/frontline/controllers/models.rb, line 34
def delete_migration model
  'delete:migration:yes %s' % @name
end
delete_model() click to toggle source

return a command that will delete the given model. `@name` variable are set by the triggered hooks(see frontline/app.rb for hooks)

# File lib/frontline/controllers/models.rb, line 22
def delete_model
  'delete:model:yes %s' % @name
end
last_run() click to toggle source

boot effective application and get last track for given migration

# File lib/frontline/controllers/models.rb, line 86
def last_run
  Dir.chdir dst_path.root do
    migrator = Enginery::Migrator.new(dst_path.root)
    migrator.boot_app
    if track = migrator.last_run(params[:file])
      '%s on %s' % [track.first.upcase, track.last]
    else
      'Never'
    end
  end
end
migration_layout(model) click to toggle source
# File lib/frontline/controllers/models.rb, line 98
def migration_layout model
  model = models[model] || halt(400, '"%s" model does not exists' % escape_html(model))
  render_p model: model
end
post_migration(model) click to toggle source

return a command that will generate a new migration for given model. `@name` and `@setups` variables are set by the triggered hooks(see frontline/app.rb for hooks)

# File lib/frontline/controllers/models.rb, line 28
def post_migration model
  'm %s model:%s %s' % [@name, model, @setups]
end
post_model() click to toggle source

return a command that will generate a new model. `@name` and `@setups` variables are set by the triggered hooks(see frontline/app.rb for hooks)

# File lib/frontline/controllers/models.rb, line 16
def post_model
  'generate:model %s %s' % [@name, @setups]
end
post_run_datamapper_task(task, model = nil) click to toggle source

run given DataMapper migrate task and stream result to browser. see `Helpers#pty_stream` for running/streaming details.

# File lib/frontline/controllers/models.rb, line 65
def post_run_datamapper_task task, model = nil
  
  %w[auto_migrate auto_upgrade].include?(task) ||
    halt(400, 'Unknown DataMapper task "%s"' % escape_html(task))

  @uuid = params.delete('uuid')
  cmd = 'rake dm:' + task
  model && cmd << ':' << model

  stream do
    pty_stream 'modal', 'show'
    passed, failure_id = pty_spawn(cmd)
    if passed
      pty_stream 'modal', 'hide'
    else
      pty_stream 'failures', failure_id
    end
  end
end
post_run_migrations() click to toggle source

run given migration or outstanding ones if no migrations given. see `Helpers#pty_stream` for running/streaming details.

it requires `:vector` param to be set to “up” or “down”. by default it will skip already performed migrations if `:force_run` is set, it will run migrations regardless performed state. if `:force_run` NOT set, `:force_yes` option should be set to true to avoid any confirmation prompts generated by Enginery.

# File lib/frontline/controllers/models.rb, line 46
def post_run_migrations
  @uuid  = params[:uuid]
  vector = params[:vector]
  extra  = params[:force_run] ? ':f' : (params[:force_yes] ? ':y' : '')
  migrations = (params[:migrations]||[])*' '
  cmd = 'bundle exec enginery m:%s%s %s' % [vector, extra, migrations]
  stream do
    pty_stream 'modal', 'show'
    passed, failure_id = pty_spawn(cmd)
    if passed
      pty_stream 'modal', 'hide'
    else
      pty_stream 'failures', failure_id
    end
  end
end