localtower 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -32
  3. data/app/controllers/localtower/pages_controller.rb +16 -45
  4. data/app/helpers/localtower/application_helper.rb +0 -18
  5. data/app/views/layouts/localtower/application.html.erb +6 -48
  6. data/app/views/localtower/pages/_migrations.html.erb +57 -0
  7. data/app/views/localtower/pages/migrations.html.erb +3 -42
  8. data/app/views/localtower/pages/models.html.erb +5 -3
  9. data/app/views/localtower/pages/{dashboard.html.erb → schema.html.erb} +0 -0
  10. data/config/routes.rb +7 -16
  11. data/lib/localtower/generators/migration.rb +8 -67
  12. data/lib/localtower/generators/model.rb +5 -8
  13. data/lib/localtower/status.rb +12 -7
  14. data/lib/localtower/tools.rb +16 -8
  15. data/lib/localtower/version.rb +1 -1
  16. data/lib/localtower.rb +0 -1
  17. data/public/js/app.js +14 -29
  18. data/public/light-bootstrap-dashboard-master/assets/css/light-bootstrap-dashboard.css +9 -35
  19. data/public/vendor/font-awesome.min.css +4 -0
  20. data/public/vendor/highlight-js-default.min.css +9 -0
  21. data/public/vendor/highlight.min.js +1198 -0
  22. data/public/{js → vendor}/masonry.pkgd.min.js +0 -0
  23. data/spec/dummy/Gemfile +0 -1
  24. data/spec/dummy/Gemfile.lock +79 -87
  25. data/spec/dummy/app/controllers/pages_controller.rb +0 -2
  26. data/spec/dummy/app/models/user.rb +2 -0
  27. data/spec/dummy/app/views/pages/home.html.erb +0 -1
  28. data/spec/dummy/config/database.yml +1 -1
  29. data/spec/dummy/config/environments/development.rb +2 -1
  30. data/spec/dummy/db/migrate/20221115190039_create_users.rb +13 -0
  31. data/spec/dummy/db/migrate/20221115193020_change_users.rb +8 -0
  32. data/spec/dummy/db/migrate/20221115193532_change_users_at1668540931.rb +5 -0
  33. data/spec/dummy/db/migrate/20221115193605_change_users_at1668540964.rb +5 -0
  34. data/spec/dummy/db/migrate/20221115193637_change_users_at1668540996.rb +5 -0
  35. data/spec/dummy/db/migrate/20221115193642_change_users_at1668541001.rb +5 -0
  36. data/spec/dummy/db/schema.rb +29 -0
  37. data/spec/dummy/log/development.log +4313 -10257
  38. data/spec/dummy/log/localtower.log +148 -474
  39. data/spec/spec_helper.rb +17 -2
  40. metadata +24 -32
  41. data/app/views/localtower/pages/logs.html.erb +0 -84
  42. data/app/views/localtower/pages/relations.html.erb +0 -66
  43. data/app/views/localtower/pages/tasks.html.erb +0 -48
  44. data/lib/localtower/generators/relation.rb +0 -59
  45. data/lib/localtower/plugins/capture.rb +0 -197
  46. data/lib/tasks/localtower_tasks.rake +0 -4
  47. data/spec/dummy/lib/playground.rb +0 -0
  48. data/spec/dummy/log/localtower_capture_d8979d360722798f7b6eb1a2694a3791.json +0 -1
  49. data/spec/dummy/log/test.log +0 -281
  50. data/spec/dummy/tmp/pids/server.pid +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6eca3e0577b9e6f78d4982d046a3cba50519ee9eddc87367e6f04ce0abe77134
4
- data.tar.gz: 7df1c8a2b27f095c840cab877023b9920290795d4b257e8c51ce0cff5730d484
3
+ metadata.gz: 0f287a30405aef9188949f37fa3142997d91e188fa0d71db42ba550d47a73bc7
4
+ data.tar.gz: 9ba53f02eefe31b6f6f1901c2dc3b8a17461a72db8086fb2bd845ec7979fde7b
5
5
  SHA512:
6
- metadata.gz: e8a389075ad641b51eddf4b41ef0a16b49ba8761c09e696edb94832e5b69896fbe051f8458110761e9767979a276e566c04fe162a6fedec6b5487158a3680802
7
- data.tar.gz: 5b05a0e034ae8c636ccc514423e4434583568440785295963da345cf30a414e4fac11462d39c8fede9e3420e913d8dd02808688e6dd19c2160f7dfd2583ffae8
6
+ metadata.gz: 122fd3997f2540a5fe239cadf8790975c5d881ad85ed4f632f99d53f94719832404b8ce265844f9da00f21661425106c74a6423b608bbdcb649002af6d963789
7
+ data.tar.gz: 8f6c8eda883c0e0dc54f1b9b218cfbd41c5dc15c36ab8ec481ffe1e2c241cefa04714c3f468d0b47556dee5576a18e69b4e42e2c46ad52850ffbb54fb332f641
data/README.md CHANGED
@@ -22,24 +22,15 @@ Compatibility:
22
22
  ### Create a migration
23
23
  ![Migrations](https://raw.githubusercontent.com/damln/localtower/master/public/screenshots/v0.1.6/4_migrations.png)
24
24
 
25
- ### Using the Capture plugin
26
- ![Capture](https://raw.githubusercontent.com/damln/localtower/master/public/screenshots/v0.1.6/5_capture.png)
27
-
28
25
  ## INSTALL
29
26
 
30
- Only tested with Rails 4.2 and Rails 5.1 (should work with any Rails 4.2+ application). Only tested with PostgreSQL.
27
+ Should work with any Rails 4.2+ application.
28
+ Only tested with PostgreSQL.
31
29
 
32
30
  Add to your `Gemfile` file:
33
31
  ```ruby
34
32
  group :development do
35
- gem "localtower", ">= 0.4.1"
36
- end
37
- ```
38
-
39
- If you want the latest master branch, add to your `Gemfile` file following:
40
- ```ruby
41
- group :development do
42
- gem "localtower", github: "damln/localtower"
33
+ gem "localtower"
43
34
  end
44
35
  ```
45
36
 
@@ -60,34 +51,27 @@ MyApp::Application.routes.draw do
60
51
  end
61
52
  ```
62
53
 
63
- ## Usage
64
-
65
- Open your browser at [http://localhost:3000/localtower](http://localhost:3000/localtower).
66
-
67
- ## Logger Usage (Capture plugin)
68
-
69
- You can put this line anywhere in your code:
54
+ /!\ IMPORTANT /!\
55
+ Change your config/environments/development.rb:
70
56
 
71
57
  ```ruby
72
- Localtower::Plugins::Capture.new(self, binding).save
73
- ```
58
+ Rails.application.configure do
59
+ # ...
74
60
 
75
- For example:
61
+ # This is the default:
62
+ # config.active_record.migration_error = :page_load
76
63
 
77
- ```ruby
78
- def my_method
79
- user = User.find(1)
80
- some_data = {foo: "bar"}
64
+ # Change it to:
65
+ config.active_record.migration_error = false if defined?(Localtower)
81
66
 
82
- Localtower::Plugins::Capture.new(self, binding).save
67
+ # ...
83
68
  end
84
69
  ```
85
70
 
86
- Then go to the Localtower intercave here: [http://localhost:3000/localtower/logs](http://localhost:3000/localtower/logs) and you will see the variables `user` and `some_data` in the UI.
71
+ ## Usage
87
72
 
88
- ### Notes for the Capture plugin:
73
+ Open your browser at [http://localhost:3000/localtower](http://localhost:3000/localtower).
89
74
 
90
- The value for each variable will try to call `.to_json`. If you have a huge collection of models likes `@users` you will see all the collection as an Array.
91
75
 
92
76
  ## Run test
93
77
 
@@ -110,7 +94,7 @@ bundle exec rspec spec/
110
94
 
111
95
  Thanks for reporting issues, I'll do my best 💪
112
96
 
113
- [![Analytics](https://ga-beacon.appspot.com/UA-93841935-1/github-readme?pixel)](https://github.com/damln/localtower)
97
+ ![ga](https://www.google-analytics.com/collect?v=1&tid=G-1XG3EBE2DZ&cid=555&aip=1&t=event&ec=github&ea=visit&dp=readme&dt=gem)
114
98
 
115
99
 
116
100
  ## Deploy
@@ -124,4 +108,3 @@ Do not hesitate to open issues if you have troubles using the gem.
124
108
 
125
109
  - By Damian Le Nouaille Diez: https://damln.com
126
110
  - Link on RubyGems: https://rubygems.org/gems/localtower
127
-
@@ -2,82 +2,53 @@ require_dependency 'localtower/application_controller'
2
2
 
3
3
  module Localtower
4
4
  class PagesController < ApplicationController
5
+ before_action :set_migrations, only: [:migrations, :models]
5
6
 
6
- def dashboard
7
- end
8
-
9
- def logs
10
- @logs = Localtower::Plugins::Capture.new.logs
11
- end
12
-
13
- def log
14
- file_content = Localtower::Plugins::Capture.log_from_md5(clean_params['md5'])
15
-
16
- render json: file_content
17
- end
18
-
19
- def log_var
20
- file_content = Localtower::Plugins::Capture.log_from_md5(clean_params['md5'])
21
- returned = file_content["variables"].select {|i| i["event_name"] == clean_params[:var] }[0]["returned"]
22
-
23
- render json: returned
7
+ def schema
24
8
  end
25
9
 
26
10
  def migrations
27
- @migrations = ::Localtower::Status.new.run
28
11
  end
29
12
 
30
13
  def post_migrations
31
14
  # Because we have a list or a field, take the item from the list in priority
32
- clean_params["migrations"]["migrations"] = clean_params["migrations"]["migrations"].map do |action_line|
15
+ migrations = clean_params["migrations"]["migrations"].map do |action_line|
16
+ # This is used for "rename_column" action:
33
17
  action_line["new_column_type"] = action_line["column_type"]
34
18
 
35
- if action_line["column"].present?
36
- action_line["column"] = action_line["column"]
37
- end
38
-
39
19
  if action_line["column_list"].present?
40
20
  action_line["column"] = action_line["column_list"]
41
21
  end
42
22
 
43
23
  action_line.delete("column_list")
24
+ # / This is used for "rename_column" action
44
25
 
45
26
  action_line
46
27
  end
47
28
 
48
- use_generator(::Localtower::Generators::Migration, clean_params["migrations"])
29
+ use_generator(::Localtower::Generators::Migration, { 'migrations' => migrations })
49
30
  redirect_to migrations_path
50
31
  end
51
32
 
52
- def relations
53
- @need_models = ::Localtower::Tools.enought_models_for_relation?
54
- end
55
-
56
- def post_relations
57
- use_generator(::Localtower::Generators::Relation, clean_params["relations"])
58
- redirect_to relations_path
59
- end
60
-
61
- # def tasks
62
- # @tasks = ['rake db:migrate RAILS_ENV=test']
63
- # end
64
-
65
- # def post_tasks
66
- # ::Localtower::Tools.perform_cmd(clean_params["task"]["name"], false)
67
-
68
- # redirect_to tasks_path
69
- # end
70
-
71
33
  def models
72
34
  end
73
35
 
74
36
  def post_models
75
37
  use_generator(::Localtower::Generators::Model, clean_params["models"])
76
- redirect_to relations_path
38
+ redirect_to models_path
39
+ end
40
+
41
+ def post_actions
42
+ ::Localtower::Tools.perform_cmd(clean_params['cmd'], false)
43
+ redirect_back fallback_location: root_path
77
44
  end
78
45
 
79
46
  private
80
47
 
48
+ def set_migrations
49
+ @migrations = ::Localtower::Status.new.run.select { |entry| entry['status'] == :todo }
50
+ end
51
+
81
52
  def use_generator(generator_klass, options)
82
53
  generator_klass.new(options).run
83
54
  end
@@ -1,25 +1,7 @@
1
1
  module Localtower
2
2
  module ApplicationHelper
3
- def subl_link_to(name, file, &block)
4
- name ||= file
5
- if block_given?
6
- str = capture(&block)
7
- else
8
- str = name
9
- end
10
-
11
- link_to str, file_link(file)
12
- end
13
-
14
3
  def file_link(file)
15
4
  "vscode://file/#{file}"
16
- # "vscode://open?url=file://#{file}&line=1"
17
- end
18
-
19
- def to_json_print(hash)
20
- # str = hash.to_json
21
- # str.gsub(/,"/, ',<br>"').gsub(/\"\:/, '": ').html_safe
22
- hash.to_json
23
5
  end
24
6
  end
25
7
  end
@@ -12,10 +12,10 @@
12
12
  <link rel="stylesheet" type="text/css" href="/light-bootstrap-dashboard-master/assets/css/light-bootstrap-dashboard.css">
13
13
 
14
14
  <!-- Fonts and icons -->
15
- <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
16
- <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
15
+ <link href="/vendor/font-awesome.min.css" rel="stylesheet">
17
16
  <link rel="stylesheet" type="text/css" href="/light-bootstrap-dashboard-master/assets/css/pe-icon-7-stroke.css">
18
17
 
18
+ <link rel="stylesheet" type="text/css" href="/vendor/highlight-js-default.min.css">
19
19
  <link rel="stylesheet" type="text/css" href="/css/app.css">
20
20
 
21
21
  <%= csrf_meta_tags %>
@@ -28,8 +28,8 @@
28
28
 
29
29
  <div class="sidebar-wrapper">
30
30
  <ul class="nav">
31
- <li class="<%= is_active_link?(dashboard_path, :inclusive) ? "active" : nil %>">
32
- <a href="<%= dashboard_path %>">
31
+ <li class="<%= is_active_link?(schema_path, :inclusive) ? "active" : nil %>">
32
+ <a href="<%= schema_path %>">
33
33
  <i class="pe-7s-home"></i>
34
34
  <p>Schema</p>
35
35
  </a>
@@ -42,59 +42,16 @@
42
42
  </a>
43
43
  </li>
44
44
 
45
- <li class="<%= is_active_link?(relations_path, :inclusive) ? "active" : nil %>">
46
- <a href="<%= relations_path %>">
47
- <i class="pe-7s-shuffle"></i>
48
- <p>New Relation</p>
49
- </a>
50
- </li>
51
-
52
45
  <li class="<%= is_active_link?(migrations_path, :inclusive) ? "active" : nil %>">
53
46
  <a href="<%= migrations_path %>">
54
47
  <i class="pe-7s-edit"></i>
55
48
  <p>New Migration</p>
56
49
  </a>
57
50
  </li>
58
-
59
- <li class="<%= is_active_link?(logs_path, :inclusive) ? "active" : nil %>">
60
- <a href="<%= logs_path %>">
61
- <i class="pe-7s-ticket"></i>
62
- <p>Logs</p>
63
- </a>
64
- </li>
65
51
  </ul>
66
52
  </div>
67
53
  </div>
68
- <div class="tower-nav">
69
- <div class="<%= is_active_link?(dashboard_path, :inclusive) ? "active" : nil %>">
70
- <a class="tower-a" href="<%= dashboard_path %>">
71
- <i class="pe-7s-home"></i>
72
- <p>Schema</p>
73
- </a>
74
- </div>
75
-
76
54
 
77
- <div class="<%= is_active_link?(models_path, :inclusive) ? "active" : nil %>">
78
- <a class="tower-a" href="<%= models_path %>">
79
- <i class="pe-7s-server"></i>
80
- <p>New Model</p>
81
- </a>
82
- </div>
83
-
84
- <div class="<%= is_active_link?(relations_path, :inclusive) ? "active" : nil %>">
85
- <a class="tower-a" href="<%= relations_path %>">
86
- <i class="pe-7s-shuffle"></i>
87
- <p>New Relation</p>
88
- </a>
89
- </div>
90
-
91
- <div class="<%= is_active_link?(migrations_path, :inclusive) ? "active" : nil %>">
92
- <a class="tower-a" href="<%= migrations_path %>">
93
- <i class="pe-7s-edit"></i>
94
- <p>New Migration</p>
95
- </a>
96
- </div>
97
- </div>
98
55
 
99
56
  <div class="main-panel">
100
57
  <div class="content">
@@ -134,7 +91,8 @@
134
91
 
135
92
  <!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
136
93
  <script src="/light-bootstrap-dashboard-master/assets/js/light-bootstrap-dashboard.js"></script>
137
- <script src="/js/masonry.pkgd.min.js"></script>
94
+ <script src="/vendor/highlight.min.js"></script>
95
+ <script src="/vendor/masonry.pkgd.min.js"></script>
138
96
  <script src="/js/app.js"></script>
139
97
  </body>
140
98
  </html>
@@ -0,0 +1,57 @@
1
+ <div class="card">
2
+ <div class="header">
3
+ <div class="container-fluid">
4
+ <div class="row">
5
+ <div class="col-md-6"><h4 class="title">Pending migrations</h4></div>
6
+ <div class="col-md-6">
7
+ <div class="pull-right">
8
+ <% if migrations.any? %>
9
+ <%= form_tag actions_path, class: "form" do %>
10
+ <button name="cmd" type="submit" value="rails db:migrate" class="btn btn-warning" data-selector="submit">
11
+ Run Pending Migrations (<code>bundle exec rails db:migrate</code>)
12
+ </button>
13
+ <% end %>
14
+ <% end %>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="content">
22
+ <% if migrations.any? %>
23
+ <% migrations.each do |entry| %>
24
+ <div class="container-fluid">
25
+ <div class="row">
26
+ <div class="col-md-8">
27
+ <h5 style="color: <%= entry['status'] == :todo ? 'red' : 'green' %>;">
28
+ <% if entry['status'] == :todo %>
29
+ <button type="button" class="btn btn-danger btn-xs">PENDING</button>
30
+ <% end %>
31
+
32
+ <a href="<%= file_link(entry['file_full_path']) %>"><%= entry['name'] %></a>
33
+ </h5>
34
+ </div>
35
+ </div>
36
+
37
+ <div class="row">
38
+ <div class="col-md-12">
39
+ <% if entry['status'] == :todo %>
40
+ <pre><code class="language-ruby"><%= entry['content'] %></code></pre>
41
+ <% end %>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ <% end %>
46
+
47
+ <% else %>
48
+ <div class="container-fluid">
49
+ <div class="row">
50
+ <div class="col-md-8">
51
+ No pending migrations.
52
+ </div>
53
+ </div>
54
+ </div>
55
+ <% end %>
56
+ </div>
57
+ </div>
@@ -76,11 +76,10 @@
76
76
 
77
77
  <hr>
78
78
 
79
- <!-- multiple lines: -->
80
79
  <div class="row">
81
80
  <div class="col-md-12 text-center">
82
- <button name="migrations[run_migrate]" type="submit" value="true" class="btn btn-success" data-selector="submit">
83
- Create the migration and <b>migrate</b>
81
+ <button type="submit" value="true" class="btn btn-success" data-selector="submit">
82
+ Create the migration
84
83
  </button>
85
84
  </div>
86
85
  </div>
@@ -88,44 +87,6 @@
88
87
  </div>
89
88
  </div>
90
89
 
91
- <div class="card">
92
- <div class="header">
93
- <h4 class="title">Migrations</h4>
94
- </div>
95
-
96
- <div class="content">
97
- <table class="table">
98
- <thead>
99
- <tr>
100
- <th>Name</th>
101
- <th>Date</th>
102
- <th>Status</th>
103
- </tr>
104
-
105
- </thead>
106
- <tbody>
107
- <% @migrations.each do |entry| %>
108
- <%
109
- klass = (entry["status"] == :done) ? "success" : "danger"
110
- %>
111
- <tr class="<%= klass %>">
112
- <td>
113
- <%= entry["name"] %>
114
- </td>
115
-
116
- <td>
117
- <%= entry["time"] %>
118
- </td>
119
-
120
- <td>
121
- <%= entry["status"] == :done ? 'done' : 'not executed' %>
122
- </td>
123
- </tr>
124
- <% end %>
125
- </tbody>
126
- </table>
127
- </div>
128
-
129
- </div>
90
+ <%= render partial: "migrations", locals: { migrations: @migrations } %>
130
91
  </div>
131
92
  </div>
@@ -14,7 +14,7 @@
14
14
  <div class="col-md-6">
15
15
  <div class="form-group">
16
16
  <label>Name of the Model</label>
17
- <input type="text" name="models[model_name]" class="form-control">
17
+ <input type="text" data-sain name="models[model_name]" class="form-control">
18
18
  </div>
19
19
  </div>
20
20
  </div>
@@ -66,13 +66,15 @@
66
66
  <!-- multiple lines: -->
67
67
  <div class="row">
68
68
  <div class="col-md-12 text-center">
69
- <button name="models[run_migrate]" type="submit" value="true" class="btn btn-success" data-selector="submit">
70
- Create the model and <b>migrate</b>
69
+ <button type="submit" value="true" class="btn btn-success" data-selector="submit">
70
+ Create the model Only
71
71
  </button>
72
72
  </div>
73
73
  </div>
74
74
  <% end %>
75
75
  </div>
76
76
  </div>
77
+
78
+ <%= render partial: "migrations", locals: { migrations: @migrations } %>
77
79
  </div>
78
80
  </div>
data/config/routes.rb CHANGED
@@ -1,22 +1,13 @@
1
1
  Localtower::Engine.routes.draw do
2
- get "migrations", to: "pages#migrations", as: :migrations
3
- post "migrations", to: "pages#post_migrations"
2
+ get 'migrations', to: 'pages#migrations', as: :migrations
3
+ post 'migrations', to: 'pages#post_migrations'
4
4
 
5
- get "models", to: "pages#models", as: :models
6
- post "models", to: "pages#post_models"
7
-
8
- get "relations", to: "pages#relations", as: :relations
9
- post "relations", to: "pages#post_relations"
10
-
11
- # get "tasks", to: "pages#tasks", as: :tasks
12
- # post "tasks", to: "pages#post_tasks"
5
+ get 'models', to: 'pages#models', as: :models
6
+ post 'models', to: 'pages#post_models'
13
7
 
14
8
  # get ':v/:asset', to: 'pages#asset_render', as: 'asset_render', :constraints => { :v => /[^\/]*/, :asset => /[^\/]*/ }
9
+ get 'schema', to: 'pages#schema', as: 'schema'
10
+ post 'actions', to: 'pages#post_actions', as: 'actions'
15
11
 
16
- get 'dashboard', to: 'pages#dashboard', as: 'dashboard'
17
- get 'logs', to: 'pages#logs', as: 'logs'
18
- get 'logs/:md5', to: 'pages#log', as: 'log'
19
- get 'logs/:md5/:var', to: 'pages#log_var', as: 'log_var'
20
-
21
- root :to => redirect('dashboard')
12
+ root :to => redirect('models')
22
13
  end
@@ -5,9 +5,11 @@ module Localtower
5
5
  include Thor::Actions
6
6
 
7
7
  no_commands do
8
+ # data = {last_migration_file: "", column_type: "", table_name: "", column: "", nullable: true, index: true}
8
9
  def migration_add_column(data)
9
10
  file = data["last_migration_file"]
10
11
 
12
+ # Special case for array
11
13
  if %w(array).include?(data["column_type"])
12
14
  line = " add_column :#{data['table_name']}, :#{data['column']}, :text"
13
15
  line << ", default: []"
@@ -134,14 +136,12 @@ module Localtower
134
136
  'change_column_type',
135
137
  'add_index_to_column',
136
138
  'belongs_to',
137
- # 'add_index_to_column_combined',
138
139
  'remove_index_to_column',
139
- # 'create_table',
140
140
  'drop_table',
141
141
  ].freeze
142
142
 
143
143
  DEFAULTS = [
144
- "true", "false", "nil"
144
+ "true", "false", "nil", "0"
145
145
  ]
146
146
 
147
147
  # @opts =
@@ -150,21 +150,12 @@ module Localtower
150
150
  @opts = JSON[opts.to_json]
151
151
  end
152
152
 
153
- def remove_all_migrations
154
- Dir["#{Rails.root}/db/migrate/*"].each { |migration_file| File.delete(migration_file) }
155
-
156
- content_schema = """
157
- ActiveRecord::Schema.define(version: 0) do
158
- end
159
- """
160
-
161
- File.open("#{Rails.root}/db/schema.rb", "w") do |f|
162
- f.write(content_schema)
163
- end
164
- end
165
-
153
+ # @opts['migrations'] = []
154
+ # @opts['run_migrate'] = true
166
155
  def run
167
- cmd = "ChangeTheModel#{@opts['migration_name']}AtTime#{Time.now.to_i}"
156
+ model_names = @opts['migrations'].map { |line| line['table_name'].camelize }.join
157
+
158
+ cmd = "Change#{model_names}#{@opts['migration_name']}At#{Time.now.to_i}"
168
159
  ::Localtower::Tools.perform_migration(cmd, true)
169
160
 
170
161
  @opts['migrations'].each do |action_line|
@@ -188,7 +179,6 @@ end
188
179
  'change_column_type' => -> { change_column_type(action_line) },
189
180
  'add_index_to_column' => -> { add_index_to_column(action_line) },
190
181
  'belongs_to' => -> { belongs_to(action_line) },
191
- # 'add_index_to_column_combined' => -> { add_index_to_column_combined(action_line) },
192
182
  'remove_index_to_column' => -> { remove_index_to_column(action_line) },
193
183
  'create_table' => -> { create_table(action_line) },
194
184
  'drop_table' => -> { drop_table(action_line) }
@@ -209,90 +199,41 @@ end
209
199
  private
210
200
 
211
201
  def add_column(data)
212
- if not data["table_name"].present? \
213
- or not data["column"].present? \
214
- or not data["column_type"].present?
215
- return nil
216
- end
217
-
218
202
  @thor.migration_add_column(data)
219
203
  end
220
204
 
221
205
  def remove_column(data)
222
- if not data["table_name"].present? \
223
- or not data["column"].present?
224
- return nil
225
- end
226
-
227
206
  @thor.migration_remove_column(data)
228
207
  end
229
208
 
230
209
  def rename_column(data)
231
- if not data["table_name"].present? \
232
- or not data["column"].present? \
233
- or not data["new_column_name"].present?
234
- return nil
235
- end
236
-
237
210
  @thor.migration_rename_column(data)
238
211
  end
239
212
 
240
213
  def change_column_type(data)
241
- if not data["table_name"].present? \
242
- or not data["column"].present? \
243
- or not data["new_column_type"].present?
244
- return nil
245
- end
246
-
247
214
  @thor.migration_change_column_type(data)
248
215
  end
249
216
 
250
217
  def add_index_to_column(data)
251
- if not data["table_name"].present? \
252
- or not data["column"].present?
253
- return nil
254
- end
255
-
256
218
  @thor.migration_add_index_to_column(data)
257
219
  end
258
220
 
259
221
  def belongs_to(data)
260
- if not data["table_name"].present? and data["belongs_to"].present?
261
- return nil
262
- end
263
-
264
222
  data["column"] = data["belongs_to"].underscore.singularize
265
223
  data['column_type'] = "references"
266
224
 
267
225
  @thor.migration_belongs_to(data)
268
226
  end
269
227
 
270
- # def add_index_to_column_combined(data)
271
- # @thor.migration_add_index_to_column_combined(data)
272
- # end
273
-
274
228
  def remove_index_to_column(data)
275
- if not data["table_name"].present? \
276
- or not data["column"].present?
277
- return nil
278
- end
279
-
280
229
  @thor.migration_remove_index_to_column(data)
281
230
  end
282
231
 
283
232
  def create_table(data)
284
- if not data["table_name"].present?
285
- return nil
286
- end
287
-
288
233
  @thor.migration_create_table(data)
289
234
  end
290
235
 
291
236
  def drop_table(data)
292
- if not data["table_name"].present?
293
- return nil
294
- end
295
-
296
237
  @thor.migration_drop_table(data)
297
238
  end
298
239