ponytail 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -1
  3. data/app/assets/javascripts/ponytail/collections/migrations.coffee +3 -0
  4. data/app/assets/javascripts/ponytail/models/column.coffee +20 -19
  5. data/app/assets/javascripts/ponytail/models/{command.coffee → command/command.coffee} +0 -0
  6. data/app/assets/javascripts/ponytail/models/{create_table_command.coffee → command/create_table_command.coffee} +0 -0
  7. data/app/assets/javascripts/ponytail/models/{drop_table_command.coffee → command/drop_table_command.coffee} +0 -0
  8. data/app/assets/javascripts/ponytail/models/{rename_table_command.coffee → command/rename_table_command.coffee} +0 -0
  9. data/app/assets/javascripts/ponytail/models/{migration_file.coffee → migration.coffee} +18 -10
  10. data/app/assets/javascripts/ponytail/models/schema.coffee +3 -0
  11. data/app/assets/javascripts/ponytail/models/table.coffee +19 -18
  12. data/app/assets/javascripts/ponytail/views/migrations/migrations_index.coffee +23 -2
  13. data/app/assets/javascripts/ponytail/views/migrations/migrations_item.coffee +6 -0
  14. data/app/assets/javascripts/ponytail/views/migrations/migrations_new.coffee +7 -7
  15. data/app/assets/javascripts/ponytail/views/preview_create_file.coffee +6 -6
  16. data/app/assets/javascripts/ponytail/views/preview_migration.coffee +6 -0
  17. data/app/assets/javascripts/ponytail/views/table.coffee +1 -1
  18. data/app/assets/stylesheets/ponytail/_index.scss +4 -0
  19. data/app/assets/stylesheets/ponytail/_new.scss +12 -9
  20. data/app/assets/stylesheets/ponytail/application.scss +1 -0
  21. data/app/controllers/ponytail/migrations_controller.rb +2 -1
  22. data/app/views/ponytail/migrations/index.html.erb +8 -23
  23. data/app/views/ponytail/migrations/new.html.erb +6 -2
  24. data/app/views/ponytail/templates/_column.html.erb +2 -2
  25. data/app/views/ponytail/templates/_migrations_item.html.erb +8 -0
  26. data/app/views/ponytail/templates/_preview_migration.html.erb +8 -0
  27. data/app/views/ponytail/templates/_table.html.erb +4 -4
  28. data/lib/ponytail.rb +2 -0
  29. data/lib/ponytail/config.rb +40 -0
  30. data/lib/ponytail/migration.rb +6 -6
  31. data/lib/ponytail/schema.rb +7 -2
  32. data/lib/ponytail/version.rb +1 -1
  33. data/ponytail.gemspec +1 -0
  34. data/spec/controllers/ponytail/migrations_controller_spec.rb +6 -0
  35. data/spec/dummy/config/environments/production.rb +6 -0
  36. data/spec/javascripts/ponytail/models/{migration_file_spec.coffee → migration_spec.coffee} +4 -4
  37. data/spec/javascripts/ponytail/models/schema_spec.coffee +1 -0
  38. metadata +31 -12
  39. data/app/assets/javascripts/ponytail/collections/.keep +0 -0
  40. data/spec/dummy/config/initializers/ponytail_on_heroku.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41a7ab39f2aa8e3b19fae0b2c8e609212aea06ef
4
- data.tar.gz: 505d33b61f8e1a2c5f1aa6176d5402c98fb5ef1a
3
+ metadata.gz: 59f7bd798599001b6a83afea2223b37314e2ccec
4
+ data.tar.gz: 12275019cc9f2ea6ee9961e3f87773d3d7741c9f
5
5
  SHA512:
6
- metadata.gz: 1aab440243c8ab54f3392721b5fc6b670742ae30478e50bbb53d0f76a08042f301950f1b5df67dc60fc0d0e46ff680e547491723497d041df44633e2e1796e3c
7
- data.tar.gz: 450c4f84a0a2798e66bb552b0e79d1bc669708770065d4683d6b81651a3f6e64f52f8a36539782d547b15b014ee4b70bad2368361d740f0cb9753f4d0f26ef74
6
+ metadata.gz: 1379d3b9955b4d65c80e96dacd51f5870b6016779ebd4bb4c00fb131c701572448d7e3ee5a2e6ab1ee9aad699b8bf1ffd9c26066b9a96250d990111723513d23
7
+ data.tar.gz: ee90be75df1f697d40e86c32eee664e4741c14de2ce03727ab2c1ee6deb11c709e291f1a93bd4119956d3ef9c993f0a607eb5b69589a3d9f18d1c2db13c65632
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ponytail (0.5.0)
4
+ ponytail (0.6.0)
5
5
  coffee-rails (~> 4.0.0)
6
6
  compass-rails
7
+ font-awesome-sass
7
8
  rails (~> 4.0.0)
8
9
  sass-rails (~> 4.0.0)
9
10
 
@@ -70,6 +71,8 @@ GEM
70
71
  erubis (2.7.0)
71
72
  execjs (2.0.2)
72
73
  ffi (1.9.3)
74
+ font-awesome-sass (4.0.2)
75
+ sass-rails (>= 3.1.1)
73
76
  fssm (0.2.10)
74
77
  hike (1.2.3)
75
78
  i18n (0.6.9)
@@ -0,0 +1,3 @@
1
+ class Ponytail.Collections.Migrations extends Backbone.Collection
2
+ model: Ponytail.Models.Migration
3
+ url: '/ponytail/migrations'
@@ -1,41 +1,42 @@
1
1
  class Ponytail.Models.Column extends Backbone.Model
2
2
  defaults:
3
- type: "string",
4
3
  name: "new_column",
5
- isRemoved: false,
6
- isAdded: false,
4
+ type: "string",
7
5
 
8
- initialize: (attrs, options) ->
6
+ initialize: (attrs) ->
7
+ @attributes.isRemoved = attrs.isRemoved || false
8
+ @attributes.isAdded = attrs.isAdded || false
9
9
  @beforeType = attrs.type || ""
10
10
  @beforeName = attrs.name || ""
11
- func = _.bind(attrs.table.trigger, attrs.table, "change")
12
- @.bind("change", func)
11
+ table = @get("table")
12
+ func = _.bind(table.trigger, table, "change")
13
+ @bind("change", func)
13
14
 
14
15
  isRemoved: ->
15
- @.get("isRemoved") == true
16
+ @get("isRemoved") == true
16
17
 
17
18
  isAdded: ->
18
- @.get("isAdded") == true
19
+ @get("isAdded") == true
19
20
 
20
21
  isRename: ->
21
- @beforeName != @.get("name")
22
+ @beforeName != @get("name")
22
23
 
23
24
  isChangeType: ->
24
- @beforeType != @.get("type")
25
+ @beforeType != @get("type")
25
26
 
26
27
  getCommands: ->
27
- table = @.get("table")
28
- if @.isRemoved() && @.isAdded()
28
+ table = @get("table")
29
+ if @isRemoved() && @isAdded()
29
30
  []
30
- else if @.isRemoved()
31
+ else if @isRemoved()
31
32
  [new Ponytail.Models.Command("remove_column", ":" + table.get("name"), ":" + @beforeName)]
32
- else if @.isAdded()
33
- [new Ponytail.Models.Command("add_column", ":" + table.get("name"), ":" + @.get("name"), ":" + @.get("type"))]
33
+ else if @isAdded()
34
+ [new Ponytail.Models.Command("add_column", ":" + table.get("name"), ":" + @get("name"), ":" + @get("type"))]
34
35
  else
35
36
  commands = []
36
- if @.isRename()
37
- commands.push(new Ponytail.Models.Command("rename_column", ":" + table.get("name"), ":" + @beforeName, ":" + @.get("name")))
38
- if @.isChangeType()
39
- commands.push(new Ponytail.Models.Command("change_column", ":" + table.get("name"), ":" + @.get("name"), ":" + @.get("type")))
37
+ if @isRename()
38
+ commands.push(new Ponytail.Models.Command("rename_column", ":" + table.get("name"), ":" + @beforeName, ":" + @get("name")))
39
+ if @isChangeType()
40
+ commands.push(new Ponytail.Models.Command("change_column", ":" + table.get("name"), ":" + @get("name"), ":" + @get("type")))
40
41
 
41
42
  commands
@@ -1,33 +1,41 @@
1
- class Ponytail.Models.MigrationFile extends Backbone.Model
1
+ class Ponytail.Models.Migration extends Backbone.Model
2
2
  defaults:
3
- className: ""
4
- rawContent: ""
3
+ filename: ""
4
+ name: ""
5
+ raw_content: ""
6
+ version: 0
5
7
 
6
8
  initialize: (attrs, options) ->
7
9
  @tables = []
8
- @.bind("change:className", @.update)
10
+ @attributes["basename"] = @basename()
11
+ @bind("change:name", @update)
12
+
13
+ basename: ->
14
+ filename = @get("filename")
15
+ if filename
16
+ filename.split('/').pop()
9
17
 
10
18
  updateByTables: (tables) ->
11
19
  @tables = tables
12
- @.update()
20
+ @update()
13
21
 
14
22
  update: =>
15
23
  rawContent = [
16
- "class #{@.get("className")} < ActiveRecord::Migration",
17
- @.getContentOfClass(),
24
+ "class #{@get("name")} < ActiveRecord::Migration",
25
+ @getContentOfClass(),
18
26
  "end",
19
27
  ].join("\n")
20
- @.set({rawContent: rawContent})
28
+ @set({raw_content: rawContent})
21
29
 
22
30
  getContentOfClass: ->
23
31
  _.compact([
24
32
  "def change",
25
- @.getStringOfCommands(),
33
+ @getStringOfCommands(),
26
34
  "end",
27
35
  ]).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
28
36
 
29
37
  getStringOfCommands: ->
30
- commands = @.getCommands()
38
+ commands = @getCommands()
31
39
  commands.map((command) ->
32
40
  command.toString()
33
41
  ).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
@@ -1,2 +1,5 @@
1
1
  class Ponytail.Models.Schema extends Backbone.Model
2
2
  url: '/ponytail/schema'
3
+ defaults:
4
+ version: 0
5
+ tables: []
@@ -2,41 +2,42 @@ class Ponytail.Models.Table extends Backbone.Model
2
2
  defaults:
3
3
  name: "new_table"
4
4
  columns: []
5
- isDrop: false
6
- isCreated: false
5
+ indexes: []
7
6
 
8
- initialize: (attrs, options) ->
7
+ initialize: (attrs) ->
8
+ @attributes.isDrop = attrs.isDrop || false
9
+ @attributes.isCreated = attrs.isCreated || false
9
10
  @beforeName = attrs.name || ""
10
11
 
11
12
  isCreated: ->
12
- @.get("isCreated") == true
13
+ @get("isCreated") == true
13
14
 
14
15
  isDrop: ->
15
- @.get("isDrop") == true
16
+ @get("isDrop") == true
16
17
 
17
18
  isRename: ->
18
- @.beforeName != @.get("name")
19
+ @beforeName != @get("name")
19
20
 
20
21
  addColumn: (column) ->
21
- columns = @.get("columns")
22
+ columns = @get("columns")
22
23
  columns.push(column)
23
- @.set({columns: columns})
24
- @.trigger("change")
24
+ @set({columns: columns})
25
+ @trigger("change")
25
26
 
26
27
  getCommands: ->
27
- if (@.isCreated() && @.isDrop())
28
+ if (@isCreated() && @isDrop())
28
29
  []
29
- else if (@.isCreated() && !@.isDrop())
30
- columns = (column for column in @.get("columns") when !column.isRemoved())
31
- [new Ponytail.Models.CreateTableCommand(@.get("name"), columns)]
32
- else if (!@.isCreated() && @.isDrop())
33
- [new Ponytail.Models.DropTableCommand(@.beforeName)]
30
+ else if (@isCreated() && !@isDrop())
31
+ columns = (column for column in @get("columns") when !column.isRemoved())
32
+ [new Ponytail.Models.CreateTableCommand(@get("name"), columns)]
33
+ else if (!@isCreated() && @isDrop())
34
+ [new Ponytail.Models.DropTableCommand(@beforeName)]
34
35
  else
35
36
  commands = []
36
- if @.isRename()
37
- commands.push(new Ponytail.Models.RenameTableCommand(@beforeName, @.get("name")))
37
+ if @isRename()
38
+ commands.push(new Ponytail.Models.RenameTableCommand(@beforeName, @get("name")))
38
39
 
39
- for column in @.get("columns")
40
+ for column in @get("columns")
40
41
  commands.push(column.getCommands())
41
42
 
42
43
  _.compact(_.flatten(commands))
@@ -7,8 +7,29 @@ class Ponytail.Views.MigrationsIndex extends Backbone.View
7
7
  "click .migrate_button": "clickMigrateButton"
8
8
  "click .rollback_button": "clickRollbackButton"
9
9
 
10
- render: ->
11
- @highlightCode()
10
+ initialize: ->
11
+ @migrations = new Ponytail.Collections.Migrations()
12
+ @schema = new Ponytail.Models.Schema()
13
+
14
+ render: =>
15
+ @migrations.fetch
16
+ success: =>
17
+ @migrations.each (model) ->
18
+ v = new Ponytail.Views.MigrationsItem({model: model})
19
+ @$(".migration_files table tbody").append(v.render().el)
20
+
21
+ @schema.fetch
22
+ success: =>
23
+ for el in @$("tr")
24
+ version = $(el).find(".version").text()
25
+ if parseInt(version) == @schema.get("version")
26
+ $(el).prepend("<td>*</td>")
27
+ else
28
+ $(el).prepend("<td></td>")
29
+
30
+ v = new Ponytail.Views.PreviewMigration({model: @migrations.head()})
31
+ @$(".migration_file").replaceWith(v.render().el)
32
+ @highlightCode()
12
33
  @
13
34
 
14
35
  highlightCode: ->
@@ -0,0 +1,6 @@
1
+ class Ponytail.Views.MigrationsItem extends Backbone.View
2
+ template: (json) ->
3
+ _.template($("#migrations_item_template").html(), json)
4
+
5
+ render: ->
6
+ @setElement(@template(@model.toJSON()))
@@ -2,7 +2,7 @@ class Ponytail.Views.MigrationsNew extends Backbone.View
2
2
  events:
3
3
  "click .close a": "closeNotice"
4
4
  "click .table_name": "clickTableName"
5
- "click .new_table a": "clickNewTable"
5
+ "click .new_table": "clickNewTable"
6
6
 
7
7
  initialize: ->
8
8
  @tables = []
@@ -17,14 +17,14 @@ class Ponytail.Views.MigrationsNew extends Backbone.View
17
17
  @$(".new_table").before(v.render().el)
18
18
  @tables.push(m)
19
19
 
20
- class_name = @$(".classname input")[0].value
21
- @migrationFile = new Ponytail.Models.MigrationFile({className: class_name})
22
- new Ponytail.Views.PreviewCreateFile({el: @$(".migration_file"), model: @migrationFile})
23
- @migrationFile.update()
20
+ name = @$(".classname input")[0].value
21
+ @migration = new Ponytail.Models.Migration({name: name})
22
+ new Ponytail.Views.PreviewCreateFile({el: @$(".migration_file"), model: @migration})
23
+ @migration.update()
24
24
 
25
25
  for table in @tables
26
26
  table.bind("change", =>
27
- @migrationFile.updateByTables(@tables)
27
+ @migration.updateByTables(@tables)
28
28
  )
29
29
  @
30
30
 
@@ -44,7 +44,7 @@ class Ponytail.Views.MigrationsNew extends Backbone.View
44
44
  table = new Ponytail.Models.Table({isCreated: true})
45
45
  @tables.push(table)
46
46
  table.bind("change", =>
47
- @migrationFile.updateByTables(@tables)
47
+ @migration.updateByTables(@tables)
48
48
  )
49
49
  table.trigger("change")
50
50
 
@@ -2,18 +2,18 @@ class Ponytail.Views.PreviewCreateFile extends Backbone.View
2
2
  events:
3
3
  "click .edit_checkbox input": "clickEditCheckbox"
4
4
  "keyup .classname input": (e) ->
5
- @model.set({className: e.target.value})
5
+ @model.set({name: e.target.value})
6
6
  "keyup .raw_content textarea": (e) ->
7
- @model.set({rawContent: e.target.value})
7
+ @model.set({raw_content: e.target.value})
8
8
  "click .create_button": "clickCreateButton"
9
9
 
10
10
  initialize: ->
11
11
  @model.bind("change", @render)
12
12
 
13
13
  render: =>
14
- @$(".raw_content pre code").text(@model.get("rawContent"))
14
+ @$(".raw_content pre code").text(@model.get("raw_content"))
15
15
  if !(@$(".raw_content textarea").is(":visible"))
16
- @$(".raw_content textarea").val(@model.get("rawContent"))
16
+ @$(".raw_content textarea").val(@model.get("raw_content"))
17
17
  @highlightCode()
18
18
  @
19
19
 
@@ -31,7 +31,7 @@ class Ponytail.Views.PreviewCreateFile extends Backbone.View
31
31
  url: '/ponytail/migrations'
32
32
  data:
33
33
  ponytail_migration:
34
- name: @model.get("className")
35
- raw_content: @model.get("rawContent")
34
+ name: @model.get("name")
35
+ raw_content: @model.get("raw_content")
36
36
  type: 'POST'
37
37
  success: -> window.location.href = "/ponytail/migrations"
@@ -0,0 +1,6 @@
1
+ class Ponytail.Views.PreviewMigration extends Backbone.View
2
+ template: (json) ->
3
+ _.template($("#preview_migration_template").html(), json)
4
+
5
+ render: ->
6
+ @setElement(@template(@model.toJSON()))
@@ -9,7 +9,7 @@ class Ponytail.Views.Table extends Backbone.View
9
9
  "blur .table_name input": "blurTableName"
10
10
  "click .drop_table": "clickDropTable"
11
11
  "click .restore_table": "clickRestoreTable"
12
- "click .add_column a": "clickAddColumn"
12
+ "click .add_column": "clickAddColumn"
13
13
 
14
14
  initialize: ->
15
15
  @model.bind("change", @render)
@@ -36,6 +36,10 @@
36
36
  .raw_content {
37
37
  display: none;
38
38
  }
39
+
40
+ .delete_file {
41
+ cursor: pointer;
42
+ }
39
43
  }
40
44
 
41
45
  .migration_file {
@@ -27,19 +27,20 @@
27
27
  display: none;
28
28
  }
29
29
  }
30
- .edit_table {
31
- width: 40px;
32
- }
33
- .drop_table {
34
- width: 40px;
30
+ .edit_table i,
31
+ .drop_table i,
32
+ .restore_table i {
33
+ cursor: pointer;
34
+ margin: 0 2px;
35
35
  }
36
+
36
37
  .restore_table {
37
- width: 60px;
38
38
  display: none;
39
39
  }
40
40
  }
41
41
 
42
42
  .new_table {
43
+ cursor: pointer;
43
44
  padding: 3px;
44
45
  margin-top: 3px;
45
46
  }
@@ -72,16 +73,18 @@
72
73
  display: none;
73
74
  }
74
75
  }
75
- .remove_column {
76
- width: 60px;
76
+ .remove_column i,
77
+ .restore_column i {
78
+ cursor: pointer;
79
+ margin: 0 2px;
77
80
  }
78
81
  .restore_column {
79
- width: 60px;
80
82
  display: none;
81
83
  }
82
84
  }
83
85
 
84
86
  .add_column {
87
+ cursor: pointer;
85
88
  margin-top: 3px;
86
89
  }
87
90
  }
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  *= require github
3
+ *= require font-awesome
3
4
  */
4
5
  @import "compass";
5
6
 
@@ -2,10 +2,11 @@ module Ponytail
2
2
  class MigrationsController < ActionController::Base
3
3
  layout 'ponytail/application'
4
4
  respond_to :html, only: [:index, :new]
5
- respond_to :json, only: [:create, :destroy]
5
+ respond_to :json, only: [:index, :create, :destroy]
6
6
 
7
7
  def index
8
8
  @migrations = Migration.all
9
+ respond_with @migrations
9
10
  end
10
11
 
11
12
  def new
@@ -1,3 +1,6 @@
1
+ <%= render 'ponytail/templates/migrations_item' %>
2
+ <%= render 'ponytail/templates/preview_migration' %>
3
+
1
4
  <div class="index">
2
5
  <div class="header">
3
6
  <span>index</span>
@@ -17,31 +20,13 @@
17
20
  <div class="migration_filepath"><%= "#{Ponytail::Migration.migrations_path}/" %></div>
18
21
  <div class="migration_files">
19
22
  <table>
20
- <% @migrations.each do |migration| %>
21
- <% if migration.current? %>
22
- <tr class="current">
23
- <td>*</td>
24
- <% else %>
25
- <tr>
26
- <td></td>
27
- <% end %>
28
- <td class="filename"><%= migration.filename_only %></td>
29
- <td class="version"><%= migration.version %></td>
30
- <td class="raw_content"><%= migration.raw_content %></td>
31
- <td class="delete_file"><a href="#">x</a></td>
32
- </tr>
33
- <% end %>
23
+ <tbody>
24
+ </tbody>
34
25
  </table>
35
26
  </div>
36
27
  </div>
37
28
 
38
- <div class="migration_file">
39
- <% migration = @migrations[0] %>
40
- <div class="migration_filename"><%= migration.filename_only %></div>
41
- <div class="raw_content">
42
- <pre><code><%= migration.raw_content %></code></pre>
43
- </div>
44
- </div>
29
+ <div class="migration_file"></div>
45
30
  </div>
46
31
 
47
32
  <div class="actions">
@@ -49,12 +34,12 @@
49
34
  <button class="new_button">New</button>
50
35
  </div>
51
36
  <div class="migrate">
52
- <% if !Ponytail::Migration.check_pending? %>
37
+ <% if Ponytail.config.update_schema? %>
53
38
  <button class="migrate_button">Migrate</button>
54
39
  <% else %>
55
40
  <button class="migrate_button" disabled="disabled">Migrate</button>
56
41
  <% end %>
57
- <% if !Ponytail::Migration.check_pending? && !@migrations[0].current? %>
42
+ <% if Ponytail.config.update_schema? && !@migrations[0].current? %>
58
43
  <button class="rollback_button">Rollback</button>
59
44
  <% else %>
60
45
  <button class="rollback_button" disabled="disabled">Rollback</button>
@@ -18,7 +18,7 @@
18
18
 
19
19
  <div class="container">
20
20
  <div class="tables">
21
- <div class="new_table"><a href="#">New Table</a></div>
21
+ <div class="new_table"><i class="fa fa-plus-circle fa-fw"></i>New Table</div>
22
22
  </div>
23
23
 
24
24
  <div class="migration_file">
@@ -39,7 +39,11 @@
39
39
  </div>
40
40
 
41
41
  <div class="actions">
42
- <button class="create_button" <%= Ponytail::Migration.check_pending? ? 'disabled="disabled"' : '' %>>Create File</button>
42
+ <% if Ponytail.config.update_schema? %>
43
+ <button class="create_button">Create File</button>
44
+ <% else %>
45
+ <button class="create_button" disabled="disabled">Create File</button>
46
+ <% end %>
43
47
  </div>
44
48
  </div>
45
49
  </div>
@@ -19,6 +19,6 @@
19
19
  <span><%%= name %></span>
20
20
  <input type="text" value="<%%= name %>" />
21
21
  </div>
22
- <div class="remove_column"><a href="#">remove</a></div>
23
- <div class="restore_column"><a href="#">restore</a></div>
22
+ <div class="remove_column"><i class="fa fa-trash-o fa-fw"></i></div>
23
+ <div class="restore_column"><i class="fa fa-undo fa-fw"></i></div>
24
24
  </script>
@@ -0,0 +1,8 @@
1
+ <script type="text/template" id="migrations_item_template">
2
+ <tr>
3
+ <td class="filename"><%%= basename %></td>
4
+ <td class="version"><%%= version %></td>
5
+ <td class="raw_content"><%%= raw_content %></td>
6
+ <td class="delete_file"><i class="fa fa-trash-o fa-fw"></i></td>
7
+ </tr>
8
+ </script>
@@ -0,0 +1,8 @@
1
+ <script type="text/template" id="preview_migration_template">
2
+ <div class="migration_file">
3
+ <div class="migration_filename"><%%= basename %></div>
4
+ <div class="raw_content">
5
+ <pre><code><%%= raw_content %></code></pre>
6
+ </div>
7
+ </div>
8
+ </script>
@@ -4,11 +4,11 @@
4
4
  <span><%%= name %></span>
5
5
  <input type="text" value="<%%= name %>" />
6
6
  </div>
7
- <div class="edit_table"><a href="#">edit</a></div>
8
- <div class="drop_table"><a href="#">drop</a></div>
9
- <div class="restore_table"><a href="#">restore</a></div>
7
+ <div class="edit_table"><i class="fa fa-pencil fa-fw"></i></div>
8
+ <div class="drop_table"><i class="fa fa-trash-o fa-fw"></i></div>
9
+ <div class="restore_table"><i class="fa fa-undo fa-fw"></i></div>
10
10
  </div>
11
11
  <div class="columns">
12
- <div class="add_column"><a href="#">Add Column</a></div>
12
+ <div class="add_column"><i class="fa fa-plus-circle fa-fw"></i>Add Column</div>
13
13
  </div>
14
14
  </script>
@@ -1,7 +1,9 @@
1
1
  require 'ponytail/engine'
2
2
  require 'ponytail/migration'
3
3
  require 'ponytail/schema'
4
+ require 'ponytail/config'
4
5
  require 'ponytail/routing/mapper'
5
6
 
6
7
  require 'sass-rails'
7
8
  require 'compass-rails'
9
+ require 'font/awesome/sass'
@@ -0,0 +1,40 @@
1
+ module Ponytail
2
+ def self.configure(&block)
3
+ yield @config ||= Ponytail::Configuration.new
4
+ end
5
+
6
+ def self.config
7
+ @config
8
+ end
9
+
10
+ def self.rails4?
11
+ ActiveRecord::VERSION::MAJOR >= 4
12
+ end
13
+
14
+ def self.check_pending?
15
+ Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending)
16
+ end
17
+
18
+ class Configuration
19
+ include ActiveSupport::Configurable
20
+ config_accessor :update_schema
21
+ config_accessor :create_migration
22
+ config_accessor :delete_migration
23
+
24
+ alias :create_migration? :create_migration
25
+ alias :delete_migration? :delete_migration
26
+
27
+ # for lazy load
28
+ def update_schema
29
+ config.update_schema = config.update_schema.call if config.update_schema.respond_to?(:call)
30
+ config.update_schema
31
+ end
32
+ alias :update_schema? :update_schema
33
+ end
34
+
35
+ configure do |config|
36
+ config.update_schema = lambda { !(rails4? && check_pending?) }
37
+ config.create_migration = true
38
+ config.delete_migration = true
39
+ end
40
+ end
@@ -7,10 +7,6 @@ module Ponytail
7
7
  validates :raw_content, presence: true
8
8
 
9
9
  class << self
10
- def check_pending?
11
- ActiveRecord::VERSION::MAJOR >= 4 && Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending)
12
- end
13
-
14
10
  def all
15
11
  proxys = ActiveRecord::Migrator.migrations(migrations_paths)
16
12
  proxys.map { |p| new(name: p.name, filename: p.filename, version: p.version) }
@@ -43,7 +39,7 @@ module Ponytail
43
39
  end
44
40
 
45
41
  def save
46
- if valid?
42
+ if valid? && Ponytail.config.create_migration?
47
43
  next_filename = "#{Migration.migrations_path}/#{Migration.next_version}_#{name.underscore}.rb"
48
44
  open(next_filename, 'w') { |f| f.write(raw_content) }
49
45
  true
@@ -53,7 +49,11 @@ module Ponytail
53
49
  end
54
50
 
55
51
  def destroy
56
- File.delete(filename)
52
+ if Ponytail.config.delete_migration?
53
+ File.delete(filename)
54
+ else
55
+ false
56
+ end
57
57
  end
58
58
 
59
59
  def current?
@@ -12,14 +12,19 @@ module Ponytail
12
12
  table_names.sort.map do |t|
13
13
  {
14
14
  name: t,
15
- columns: ActiveRecord::Base.connection.columns(t)
15
+ columns: ActiveRecord::Base.connection.columns(t),
16
+ indexes: ActiveRecord::Base.connection.indexes(t)
16
17
  }
17
18
  end
18
19
  end
19
20
 
20
21
  def update(attrs)
21
22
  @version = attrs["version"].to_i
22
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, @version)
23
+ if Ponytail.config.update_schema?
24
+ ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, @version)
25
+ else
26
+ false
27
+ end
23
28
  end
24
29
 
25
30
  def as_json(attrs)
@@ -1,3 +1,3 @@
1
1
  module Ponytail
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'coffee-rails', '~> 4.0.0'
23
23
  spec.add_dependency 'sass-rails', '~> 4.0.0'
24
24
  spec.add_dependency 'compass-rails'
25
+ spec.add_dependency 'font-awesome-sass'
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.3"
27
28
  spec.add_development_dependency "rake"
@@ -20,6 +20,12 @@ module Ponytail
20
20
  it { expect(response.status).to eq(200) } # ok
21
21
  end
22
22
 
23
+ describe "#index.json" do
24
+ before { get :index, format: :json }
25
+ it { expect(response).to be_success }
26
+ it { expect(response.status).to eq(200) } # ok
27
+ end
28
+
23
29
  describe "#create.json" do
24
30
  context "valid params" do
25
31
  before do
@@ -77,4 +77,10 @@ Dummy::Application.configure do
77
77
 
78
78
  # Use default logging formatter so that PID and timestamp are not suppressed.
79
79
  config.log_formatter = ::Logger::Formatter.new
80
+
81
+ Ponytail.configure do |config|
82
+ config.update_schema = false
83
+ config.create_migration = false
84
+ config.delete_migration = false
85
+ end
80
86
  end
@@ -1,7 +1,7 @@
1
- describe "MigrationFile", ->
1
+ describe "Migration", ->
2
2
  describe "#update", ->
3
- it "should be able to set rawContent", ->
4
- mFile = new Ponytail.Models.MigrationFile({className: "CreateUsers"})
3
+ it "should be able to set raw_content", ->
4
+ mFile = new Ponytail.Models.Migration({name: "CreateUsers"})
5
5
  spyOn(mFile, "getContentOfClass").andReturn("")
6
6
  expected = [
7
7
  "class CreateUsers < ActiveRecord::Migration",
@@ -9,5 +9,5 @@ describe "MigrationFile", ->
9
9
  "end",
10
10
  ].join("\n")
11
11
  mFile.update()
12
- actual = mFile.get("rawContent")
12
+ actual = mFile.get("raw_content")
13
13
  expect(actual).toBe(expected)
@@ -0,0 +1 @@
1
+ describe 'Schema', ->
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ponytail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-07 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: font-awesome-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -182,21 +196,23 @@ files:
182
196
  - README.md
183
197
  - Rakefile
184
198
  - app/assets/javascripts/ponytail/application.js
185
- - app/assets/javascripts/ponytail/collections/.keep
199
+ - app/assets/javascripts/ponytail/collections/migrations.coffee
186
200
  - app/assets/javascripts/ponytail/models/column.coffee
187
- - app/assets/javascripts/ponytail/models/command.coffee
188
- - app/assets/javascripts/ponytail/models/create_table_command.coffee
189
- - app/assets/javascripts/ponytail/models/drop_table_command.coffee
190
- - app/assets/javascripts/ponytail/models/migration_file.coffee
191
- - app/assets/javascripts/ponytail/models/rename_table_command.coffee
201
+ - app/assets/javascripts/ponytail/models/command/command.coffee
202
+ - app/assets/javascripts/ponytail/models/command/create_table_command.coffee
203
+ - app/assets/javascripts/ponytail/models/command/drop_table_command.coffee
204
+ - app/assets/javascripts/ponytail/models/command/rename_table_command.coffee
205
+ - app/assets/javascripts/ponytail/models/migration.coffee
192
206
  - app/assets/javascripts/ponytail/models/schema.coffee
193
207
  - app/assets/javascripts/ponytail/models/table.coffee
194
208
  - app/assets/javascripts/ponytail/ponytail.coffee
195
209
  - app/assets/javascripts/ponytail/routers/.keep
196
210
  - app/assets/javascripts/ponytail/views/column.coffee
197
211
  - app/assets/javascripts/ponytail/views/migrations/migrations_index.coffee
212
+ - app/assets/javascripts/ponytail/views/migrations/migrations_item.coffee
198
213
  - app/assets/javascripts/ponytail/views/migrations/migrations_new.coffee
199
214
  - app/assets/javascripts/ponytail/views/preview_create_file.coffee
215
+ - app/assets/javascripts/ponytail/views/preview_migration.coffee
200
216
  - app/assets/javascripts/ponytail/views/table.coffee
201
217
  - app/assets/stylesheets/ponytail/_base.scss
202
218
  - app/assets/stylesheets/ponytail/_index.scss
@@ -208,10 +224,13 @@ files:
208
224
  - app/views/ponytail/migrations/index.html.erb
209
225
  - app/views/ponytail/migrations/new.html.erb
210
226
  - app/views/ponytail/templates/_column.html.erb
227
+ - app/views/ponytail/templates/_migrations_item.html.erb
228
+ - app/views/ponytail/templates/_preview_migration.html.erb
211
229
  - app/views/ponytail/templates/_table.html.erb
212
230
  - bin/rails
213
231
  - config/routes.rb
214
232
  - lib/ponytail.rb
233
+ - lib/ponytail/config.rb
215
234
  - lib/ponytail/engine.rb
216
235
  - lib/ponytail/migration.rb
217
236
  - lib/ponytail/routing/mapper.rb
@@ -248,7 +267,6 @@ files:
248
267
  - spec/dummy/config/initializers/filter_parameter_logging.rb
249
268
  - spec/dummy/config/initializers/inflections.rb
250
269
  - spec/dummy/config/initializers/mime_types.rb
251
- - spec/dummy/config/initializers/ponytail_on_heroku.rb
252
270
  - spec/dummy/config/initializers/secret_token.rb
253
271
  - spec/dummy/config/initializers/session_store.rb
254
272
  - spec/dummy/config/initializers/wrap_parameters.rb
@@ -268,7 +286,8 @@ files:
268
286
  - spec/javascripts/ponytail/models/column_spec.coffee
269
287
  - spec/javascripts/ponytail/models/command_spec.coffee
270
288
  - spec/javascripts/ponytail/models/create_command_spec.coffee
271
- - spec/javascripts/ponytail/models/migration_file_spec.coffee
289
+ - spec/javascripts/ponytail/models/migration_spec.coffee
290
+ - spec/javascripts/ponytail/models/schema_spec.coffee
272
291
  - spec/javascripts/ponytail/models/table_spec.coffee
273
292
  - spec/javascripts/support/boots/boot.coffee
274
293
  - spec/javascripts/support/coffee-script.js
@@ -342,7 +361,6 @@ test_files:
342
361
  - spec/dummy/config/initializers/filter_parameter_logging.rb
343
362
  - spec/dummy/config/initializers/inflections.rb
344
363
  - spec/dummy/config/initializers/mime_types.rb
345
- - spec/dummy/config/initializers/ponytail_on_heroku.rb
346
364
  - spec/dummy/config/initializers/secret_token.rb
347
365
  - spec/dummy/config/initializers/session_store.rb
348
366
  - spec/dummy/config/initializers/wrap_parameters.rb
@@ -362,7 +380,8 @@ test_files:
362
380
  - spec/javascripts/ponytail/models/column_spec.coffee
363
381
  - spec/javascripts/ponytail/models/command_spec.coffee
364
382
  - spec/javascripts/ponytail/models/create_command_spec.coffee
365
- - spec/javascripts/ponytail/models/migration_file_spec.coffee
383
+ - spec/javascripts/ponytail/models/migration_spec.coffee
384
+ - spec/javascripts/ponytail/models/schema_spec.coffee
366
385
  - spec/javascripts/ponytail/models/table_spec.coffee
367
386
  - spec/javascripts/support/boots/boot.coffee
368
387
  - spec/javascripts/support/coffee-script.js
@@ -1,19 +0,0 @@
1
- if Rails.env.production?
2
- module Ponytail
3
- class Migration
4
- def save
5
- valid?
6
- end
7
-
8
- def destroy
9
- false
10
- end
11
- end
12
-
13
- class Schema
14
- def update(attrs)
15
- true
16
- end
17
- end
18
- end
19
- end