ponytail 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/app/assets/javascripts/ponytail/collections/migrations.coffee +3 -0
- data/app/assets/javascripts/ponytail/models/column.coffee +20 -19
- data/app/assets/javascripts/ponytail/models/{command.coffee → command/command.coffee} +0 -0
- data/app/assets/javascripts/ponytail/models/{create_table_command.coffee → command/create_table_command.coffee} +0 -0
- data/app/assets/javascripts/ponytail/models/{drop_table_command.coffee → command/drop_table_command.coffee} +0 -0
- data/app/assets/javascripts/ponytail/models/{rename_table_command.coffee → command/rename_table_command.coffee} +0 -0
- data/app/assets/javascripts/ponytail/models/{migration_file.coffee → migration.coffee} +18 -10
- data/app/assets/javascripts/ponytail/models/schema.coffee +3 -0
- data/app/assets/javascripts/ponytail/models/table.coffee +19 -18
- data/app/assets/javascripts/ponytail/views/migrations/migrations_index.coffee +23 -2
- data/app/assets/javascripts/ponytail/views/migrations/migrations_item.coffee +6 -0
- data/app/assets/javascripts/ponytail/views/migrations/migrations_new.coffee +7 -7
- data/app/assets/javascripts/ponytail/views/preview_create_file.coffee +6 -6
- data/app/assets/javascripts/ponytail/views/preview_migration.coffee +6 -0
- data/app/assets/javascripts/ponytail/views/table.coffee +1 -1
- data/app/assets/stylesheets/ponytail/_index.scss +4 -0
- data/app/assets/stylesheets/ponytail/_new.scss +12 -9
- data/app/assets/stylesheets/ponytail/application.scss +1 -0
- data/app/controllers/ponytail/migrations_controller.rb +2 -1
- data/app/views/ponytail/migrations/index.html.erb +8 -23
- data/app/views/ponytail/migrations/new.html.erb +6 -2
- data/app/views/ponytail/templates/_column.html.erb +2 -2
- data/app/views/ponytail/templates/_migrations_item.html.erb +8 -0
- data/app/views/ponytail/templates/_preview_migration.html.erb +8 -0
- data/app/views/ponytail/templates/_table.html.erb +4 -4
- data/lib/ponytail.rb +2 -0
- data/lib/ponytail/config.rb +40 -0
- data/lib/ponytail/migration.rb +6 -6
- data/lib/ponytail/schema.rb +7 -2
- data/lib/ponytail/version.rb +1 -1
- data/ponytail.gemspec +1 -0
- data/spec/controllers/ponytail/migrations_controller_spec.rb +6 -0
- data/spec/dummy/config/environments/production.rb +6 -0
- data/spec/javascripts/ponytail/models/{migration_file_spec.coffee → migration_spec.coffee} +4 -4
- data/spec/javascripts/ponytail/models/schema_spec.coffee +1 -0
- metadata +31 -12
- data/app/assets/javascripts/ponytail/collections/.keep +0 -0
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59f7bd798599001b6a83afea2223b37314e2ccec
|
4
|
+
data.tar.gz: 12275019cc9f2ea6ee9961e3f87773d3d7741c9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1379d3b9955b4d65c80e96dacd51f5870b6016779ebd4bb4c00fb131c701572448d7e3ee5a2e6ab1ee9aad699b8bf1ffd9c26066b9a96250d990111723513d23
|
7
|
+
data.tar.gz: ee90be75df1f697d40e86c32eee664e4741c14de2ce03727ab2c1ee6deb11c709e291f1a93bd4119956d3ef9c993f0a607eb5b69589a3d9f18d1c2db13c65632
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ponytail (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)
|
@@ -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
|
-
|
6
|
-
isAdded: false,
|
4
|
+
type: "string",
|
7
5
|
|
8
|
-
initialize: (attrs
|
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
|
-
|
12
|
-
|
11
|
+
table = @get("table")
|
12
|
+
func = _.bind(table.trigger, table, "change")
|
13
|
+
@bind("change", func)
|
13
14
|
|
14
15
|
isRemoved: ->
|
15
|
-
|
16
|
+
@get("isRemoved") == true
|
16
17
|
|
17
18
|
isAdded: ->
|
18
|
-
|
19
|
+
@get("isAdded") == true
|
19
20
|
|
20
21
|
isRename: ->
|
21
|
-
@beforeName !=
|
22
|
+
@beforeName != @get("name")
|
22
23
|
|
23
24
|
isChangeType: ->
|
24
|
-
@beforeType !=
|
25
|
+
@beforeType != @get("type")
|
25
26
|
|
26
27
|
getCommands: ->
|
27
|
-
table =
|
28
|
-
if
|
28
|
+
table = @get("table")
|
29
|
+
if @isRemoved() && @isAdded()
|
29
30
|
[]
|
30
|
-
else if
|
31
|
+
else if @isRemoved()
|
31
32
|
[new Ponytail.Models.Command("remove_column", ":" + table.get("name"), ":" + @beforeName)]
|
32
|
-
else if
|
33
|
-
[new Ponytail.Models.Command("add_column", ":" + table.get("name"), ":" +
|
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
|
37
|
-
commands.push(new Ponytail.Models.Command("rename_column", ":" + table.get("name"), ":" + @beforeName, ":" +
|
38
|
-
if
|
39
|
-
commands.push(new Ponytail.Models.Command("change_column", ":" + table.get("name"), ":" +
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,33 +1,41 @@
|
|
1
|
-
class Ponytail.Models.
|
1
|
+
class Ponytail.Models.Migration extends Backbone.Model
|
2
2
|
defaults:
|
3
|
-
|
4
|
-
|
3
|
+
filename: ""
|
4
|
+
name: ""
|
5
|
+
raw_content: ""
|
6
|
+
version: 0
|
5
7
|
|
6
8
|
initialize: (attrs, options) ->
|
7
9
|
@tables = []
|
8
|
-
|
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
|
-
|
20
|
+
@update()
|
13
21
|
|
14
22
|
update: =>
|
15
23
|
rawContent = [
|
16
|
-
"class #{
|
17
|
-
|
24
|
+
"class #{@get("name")} < ActiveRecord::Migration",
|
25
|
+
@getContentOfClass(),
|
18
26
|
"end",
|
19
27
|
].join("\n")
|
20
|
-
|
28
|
+
@set({raw_content: rawContent})
|
21
29
|
|
22
30
|
getContentOfClass: ->
|
23
31
|
_.compact([
|
24
32
|
"def change",
|
25
|
-
|
33
|
+
@getStringOfCommands(),
|
26
34
|
"end",
|
27
35
|
]).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
|
28
36
|
|
29
37
|
getStringOfCommands: ->
|
30
|
-
commands =
|
38
|
+
commands = @getCommands()
|
31
39
|
commands.map((command) ->
|
32
40
|
command.toString()
|
33
41
|
).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
|
@@ -2,41 +2,42 @@ class Ponytail.Models.Table extends Backbone.Model
|
|
2
2
|
defaults:
|
3
3
|
name: "new_table"
|
4
4
|
columns: []
|
5
|
-
|
6
|
-
isCreated: false
|
5
|
+
indexes: []
|
7
6
|
|
8
|
-
initialize: (attrs
|
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
|
-
|
13
|
+
@get("isCreated") == true
|
13
14
|
|
14
15
|
isDrop: ->
|
15
|
-
|
16
|
+
@get("isDrop") == true
|
16
17
|
|
17
18
|
isRename: ->
|
18
|
-
|
19
|
+
@beforeName != @get("name")
|
19
20
|
|
20
21
|
addColumn: (column) ->
|
21
|
-
columns =
|
22
|
+
columns = @get("columns")
|
22
23
|
columns.push(column)
|
23
|
-
|
24
|
-
|
24
|
+
@set({columns: columns})
|
25
|
+
@trigger("change")
|
25
26
|
|
26
27
|
getCommands: ->
|
27
|
-
if (
|
28
|
+
if (@isCreated() && @isDrop())
|
28
29
|
[]
|
29
|
-
else if (
|
30
|
-
columns = (column for column in
|
31
|
-
[new Ponytail.Models.CreateTableCommand(
|
32
|
-
else if (
|
33
|
-
[new Ponytail.Models.DropTableCommand(
|
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
|
37
|
-
commands.push(new Ponytail.Models.RenameTableCommand(@beforeName,
|
37
|
+
if @isRename()
|
38
|
+
commands.push(new Ponytail.Models.RenameTableCommand(@beforeName, @get("name")))
|
38
39
|
|
39
|
-
for column in
|
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
|
-
|
11
|
-
@
|
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: ->
|
@@ -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
|
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
|
-
|
21
|
-
@
|
22
|
-
new Ponytail.Views.PreviewCreateFile({el: @$(".migration_file"), model: @
|
23
|
-
@
|
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
|
-
@
|
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
|
-
@
|
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({
|
5
|
+
@model.set({name: e.target.value})
|
6
6
|
"keyup .raw_content textarea": (e) ->
|
7
|
-
@model.set({
|
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("
|
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("
|
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("
|
35
|
-
raw_content: @model.get("
|
34
|
+
name: @model.get("name")
|
35
|
+
raw_content: @model.get("raw_content")
|
36
36
|
type: 'POST'
|
37
37
|
success: -> window.location.href = "/ponytail/migrations"
|
@@ -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
|
12
|
+
"click .add_column": "clickAddColumn"
|
13
13
|
|
14
14
|
initialize: ->
|
15
15
|
@model.bind("change", @render)
|
@@ -27,19 +27,20 @@
|
|
27
27
|
display: none;
|
28
28
|
}
|
29
29
|
}
|
30
|
-
.edit_table
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
}
|
@@ -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
|
-
|
21
|
-
|
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
|
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
|
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"><
|
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
|
-
|
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"><
|
23
|
-
<div class="restore_column"><
|
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>
|
@@ -4,11 +4,11 @@
|
|
4
4
|
<span><%%= name %></span>
|
5
5
|
<input type="text" value="<%%= name %>" />
|
6
6
|
</div>
|
7
|
-
<div class="edit_table"><
|
8
|
-
<div class="drop_table"><
|
9
|
-
<div class="restore_table"><
|
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"><
|
12
|
+
<div class="add_column"><i class="fa fa-plus-circle fa-fw"></i>Add Column</div>
|
13
13
|
</div>
|
14
14
|
</script>
|
data/lib/ponytail.rb
CHANGED
@@ -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
|
data/lib/ponytail/migration.rb
CHANGED
@@ -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
|
-
|
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?
|
data/lib/ponytail/schema.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/ponytail/version.rb
CHANGED
data/ponytail.gemspec
CHANGED
@@ -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 "
|
1
|
+
describe "Migration", ->
|
2
2
|
describe "#update", ->
|
3
|
-
it "should be able to set
|
4
|
-
mFile = new Ponytail.Models.
|
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("
|
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.
|
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-
|
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
|
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/
|
191
|
-
- app/assets/javascripts/ponytail/models/
|
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/
|
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/
|
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
|
File without changes
|