localtower 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/views/localtower/pages/migrations.html.erb +5 -0
- data/lib/localtower/generators/migration.rb +35 -1
- data/lib/localtower/generators/model.rb +1 -1
- data/lib/localtower/tools.rb +19 -5
- data/lib/localtower/version.rb +1 -1
- data/public/js/app.js +3 -1
- data/spec/dummy/Gemfile.lock +1 -1
- data/spec/dummy/log/development.log +580 -0
- data/spec/dummy/log/localtower.log +3326 -0
- data/spec/dummy/log/test.log +2601 -0
- data/spec/factories/migration.rb +21 -0
- data/spec/lib/localtower/generators/migration_spec.rb +10 -9
- data/spec/lib/localtower/generators/model_spec.rb +2 -1
- data/spec/lib/localtower/generators/relation_spec.rb +29 -1
- data/spec/spec_helper.rb +8 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3dbaecae36ac179d94fd480b4faad357771092a3
|
|
4
|
+
data.tar.gz: 2e1e8e8647f88a275cce4a6ec5c1e0d39d807d79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01fb89e48a72b11ba7e1e1c1dad80853a5bf4271ca10b1d97bbd8ec0040370f80f87a180c6d12704cd84e8842f32aba5415c43c26c3790004f4e0a7be9c77248
|
|
7
|
+
data.tar.gz: 12567d4a250b0c3a7ca9597e0926c601ff3b66e378e070000506be6a7054ed37151cb55d9f4562b25fb09fb410ab39f3aeeadc9e13484b747ba337ab103725fb
|
data/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Localtower
|
|
2
2
|
|
|
3
|
+
### See the schema
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
### Create a model
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
### Create a many to many relation
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
### Create a migration
|
|
13
|
+

|
|
3
14
|
|
|
4
15
|
|
|
5
16
|
## INSTALL
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
<thead>
|
|
15
15
|
<th>Action</th>
|
|
16
16
|
<th>Model</th>
|
|
17
|
+
<th>Belongs To</th>
|
|
17
18
|
<th>Column</th>
|
|
18
19
|
<th>New Column Name</th>
|
|
19
20
|
<th>Type</th>
|
|
@@ -32,6 +33,10 @@
|
|
|
32
33
|
<%= select_tag "migrations[migrations][][table_name]", options_for_select(Localtower::Tools.models.collect {|p| [ p, p.table_name ] }), class: "form-control" %>
|
|
33
34
|
</td>
|
|
34
35
|
|
|
36
|
+
<td>
|
|
37
|
+
<%= select_tag "migrations[migrations][][belongs_to]", options_for_select(Localtower::Tools.models.collect {|p| [ p, p.table_name ] }), class: "form-control" %>
|
|
38
|
+
</td>
|
|
39
|
+
|
|
35
40
|
<td class="text-center">
|
|
36
41
|
<input type="text" name="migrations[migrations][][column]" class="form-control" data-selector="column_text">
|
|
37
42
|
|
|
@@ -80,6 +80,27 @@ module Localtower
|
|
|
80
80
|
inject_in_migration(file, line)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
+
def migration_belongs_to(data)
|
|
84
|
+
file = data["last_migration_file"]
|
|
85
|
+
|
|
86
|
+
line = " add_reference :#{data["table_name"]}, :#{data["column"]}, foreign_key: true, index: true\n"
|
|
87
|
+
|
|
88
|
+
inject_in_migration(file, line)
|
|
89
|
+
|
|
90
|
+
file = "#{Rails.root}/app/models/#{data["table_name"].underscore.singularize}.rb"
|
|
91
|
+
after = /class #{data["table_name"].camelize.singularize} < ApplicationRecord\n/
|
|
92
|
+
line1 = " belongs_to :#{data["column"].singularize.underscore}\n"
|
|
93
|
+
|
|
94
|
+
::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
file = "#{Rails.root}/app/models/#{data["column"].underscore.singularize}.rb"
|
|
98
|
+
after = /class #{data["column"].camelize.singularize} < ApplicationRecord\n/
|
|
99
|
+
line1 = " has_many :#{data["table_name"].pluralize.underscore}\n"
|
|
100
|
+
|
|
101
|
+
::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
|
|
102
|
+
end
|
|
103
|
+
|
|
83
104
|
def migration_create_table(data)
|
|
84
105
|
file = data["last_migration_file"]
|
|
85
106
|
|
|
@@ -105,13 +126,14 @@ module Localtower
|
|
|
105
126
|
end
|
|
106
127
|
|
|
107
128
|
class Migration
|
|
108
|
-
TYPES = %w(string datetime text integer float json jsonb decimal binary boolean array references).freeze
|
|
129
|
+
TYPES = %w(string datetime text uuid integer float json jsonb decimal binary boolean array references).freeze
|
|
109
130
|
ACTIONS = [
|
|
110
131
|
'add_column',
|
|
111
132
|
'remove_column',
|
|
112
133
|
'rename_column',
|
|
113
134
|
'change_column_type',
|
|
114
135
|
'add_index_to_column',
|
|
136
|
+
'belongs_to',
|
|
115
137
|
# 'add_index_to_column_combined',
|
|
116
138
|
'remove_index_to_column',
|
|
117
139
|
# 'create_table',
|
|
@@ -161,6 +183,7 @@ end
|
|
|
161
183
|
'rename_column' => -> { rename_column(action_line) },
|
|
162
184
|
'change_column_type' => -> { change_column_type(action_line) },
|
|
163
185
|
'add_index_to_column' => -> { add_index_to_column(action_line) },
|
|
186
|
+
'belongs_to' => -> { belongs_to(action_line) },
|
|
164
187
|
# 'add_index_to_column_combined' => -> { add_index_to_column_combined(action_line) },
|
|
165
188
|
'remove_index_to_column' => -> { remove_index_to_column(action_line) },
|
|
166
189
|
'create_table' => -> { create_table(action_line) },
|
|
@@ -229,6 +252,17 @@ end
|
|
|
229
252
|
@thor.migration_add_index_to_column(data)
|
|
230
253
|
end
|
|
231
254
|
|
|
255
|
+
def belongs_to(data)
|
|
256
|
+
if not data["table_name"].present? and data["belongs_to"].present?
|
|
257
|
+
return nil
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
data["column"] = data["belongs_to"].underscore.singularize
|
|
261
|
+
data['column_type'] = "references"
|
|
262
|
+
|
|
263
|
+
@thor.migration_belongs_to(data)
|
|
264
|
+
end
|
|
265
|
+
|
|
232
266
|
# def add_index_to_column_combined(data)
|
|
233
267
|
# @thor.migration_add_index_to_column_combined(data)
|
|
234
268
|
# end
|
|
@@ -26,7 +26,7 @@ module Localtower
|
|
|
26
26
|
|
|
27
27
|
if @opts['run_migrate']
|
|
28
28
|
::Localtower::Tools.perform_cmd('rake db:migrate', false)
|
|
29
|
-
::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
|
|
29
|
+
# ::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
self
|
data/lib/localtower/tools.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Localtower
|
|
|
13
13
|
|
|
14
14
|
class << self
|
|
15
15
|
def force_reload!
|
|
16
|
-
app_folders = Dir["#{Rails.root}/app/**/*.rb"]
|
|
16
|
+
app_folders = Dir["#{Rails.root}/app/models/**/*.rb"]
|
|
17
17
|
lib_folders = Dir["#{Rails.root}/lib/**/*.rb"]
|
|
18
18
|
|
|
19
19
|
all_folders = (app_folders + lib_folders).flatten
|
|
@@ -25,15 +25,19 @@ module Localtower
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def models
|
|
28
|
+
self.force_reload!
|
|
29
|
+
|
|
30
|
+
klass_parent = defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
|
|
31
|
+
|
|
28
32
|
Dir["#{Rails.root}/app/models/\*.rb"].map { |f|
|
|
29
33
|
File.basename(f, '.*').camelize.constantize
|
|
30
|
-
}.select { |klass| klass !=
|
|
34
|
+
}.select { |klass| klass != klass_parent }.select { |klass| klass.respond_to?(:columns_hash) }
|
|
31
35
|
end
|
|
32
36
|
|
|
33
37
|
def models_presented
|
|
38
|
+
self.force_reload!
|
|
39
|
+
|
|
34
40
|
list = []
|
|
35
|
-
files = Dir["#{Rails.root}/app/models/**/*.*"]
|
|
36
|
-
files.each { |file| ActiveSupport::Dependencies.require_or_load(file) }
|
|
37
41
|
|
|
38
42
|
self.models.each do |model|
|
|
39
43
|
attributes_list = []
|
|
@@ -120,13 +124,23 @@ module Localtower
|
|
|
120
124
|
self.perform_cmd("rails g migration #{str}", false)
|
|
121
125
|
|
|
122
126
|
if not standalone
|
|
127
|
+
# self.perform_raw_cmd("z rake #{cmd_str}", standalone)
|
|
123
128
|
self.perform_cmd('rake db:migrate')
|
|
124
|
-
self.perform_cmd('rake db:migrate RAILS_ENV=test')
|
|
129
|
+
# self.perform_cmd('rake db:migrate RAILS_ENV=test')
|
|
125
130
|
end
|
|
126
131
|
end
|
|
127
132
|
|
|
128
133
|
def perform_cmd(cmd_str, standalone = true)
|
|
129
134
|
self.perform_raw_cmd("bundle exec #{cmd_str}", standalone)
|
|
135
|
+
|
|
136
|
+
# if cmd_str["rake"]
|
|
137
|
+
# self.perform_raw_cmd("zeus #{cmd_str}", standalone)
|
|
138
|
+
# elsif cmd_str["rails g migration"]
|
|
139
|
+
# cmd = cmd_str.split("rails g migration")[1]
|
|
140
|
+
# self.perform_raw_cmd("zeus generate migration #{cmd}", standalone)
|
|
141
|
+
# else
|
|
142
|
+
# self.perform_raw_cmd("bundle exec #{cmd_str}", standalone)
|
|
143
|
+
# end
|
|
130
144
|
end
|
|
131
145
|
|
|
132
146
|
def perform_raw_cmd(cmd_str, standalone = false, root_dir = false)
|
data/lib/localtower/version.rb
CHANGED
data/public/js/app.js
CHANGED
|
@@ -40,6 +40,7 @@ MainApp = {
|
|
|
40
40
|
var action_input = $tr.find("[name='migrations[migrations][][action]']");
|
|
41
41
|
|
|
42
42
|
var table_name_input = $tr.find("[name='migrations[migrations][][table_name]']");
|
|
43
|
+
var belongs_to_input = $tr.find("[name='migrations[migrations][][belongs_to]']");
|
|
43
44
|
|
|
44
45
|
var column_text_input = $tr.find("[data-selector='column_text']");
|
|
45
46
|
var column_input = $tr.find("[data-selector='column_list']");
|
|
@@ -52,7 +53,7 @@ MainApp = {
|
|
|
52
53
|
var action = action_input.val();
|
|
53
54
|
|
|
54
55
|
|
|
55
|
-
$.each([column_text_input, column_input, new_column_name_input, column_type_input, index_input, nullable_input], function(i, el) {
|
|
56
|
+
$.each([belongs_to_input, column_text_input, column_input, new_column_name_input, column_type_input, index_input, nullable_input], function(i, el) {
|
|
56
57
|
el.hide();
|
|
57
58
|
});
|
|
58
59
|
|
|
@@ -62,6 +63,7 @@ MainApp = {
|
|
|
62
63
|
remove_column: [column_input],
|
|
63
64
|
rename_column: [column_input, new_column_name_input],
|
|
64
65
|
change_column_type: [column_input, column_type_input],
|
|
66
|
+
belongs_to: [belongs_to_input],
|
|
65
67
|
add_index_to_column: [column_input],
|
|
66
68
|
remove_index_to_column: [column_input],
|
|
67
69
|
drop_table: [],
|