Class: Frontline::Models

Inherits:
E
  • Object
show all
Defined in:
lib/frontline/controllers/models.rb

Instance Method Summary collapse

Instance Method Details

#delete_migration(model) ⇒ Object

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)



34
35
36
# File 'lib/frontline/controllers/models.rb', line 34

def delete_migration model
  'delete:migration:yes %s' % @name
end

#delete_modelObject

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



22
23
24
# File 'lib/frontline/controllers/models.rb', line 22

def delete_model
  'delete:model:yes %s' % @name
end

#last_runObject

boot effective application and get last track for given migration



86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object



98
99
100
101
# 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) ⇒ Object

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)



28
29
30
# File 'lib/frontline/controllers/models.rb', line 28

def post_migration model
  'm %s model:%s %s' % [@name, model, @setups]
end

#post_modelObject

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)



16
17
18
# 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) ⇒ Object

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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_migrationsObject

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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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