localtower 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -17
- data/app/controllers/localtower/pages_controller.rb +27 -12
- data/app/views/layouts/localtower/application.html.erb +16 -33
- data/app/views/localtower/pages/_alert_no_models.html.erb +3 -0
- data/app/views/localtower/pages/migrations.html.erb +52 -83
- data/app/views/localtower/pages/models.html.erb +53 -70
- data/app/views/localtower/pages/new_migration.html.erb +103 -0
- data/app/views/localtower/pages/new_model.html.erb +87 -0
- data/config/routes.rb +4 -4
- data/lib/localtower/generators/migration.rb +51 -120
- data/lib/localtower/generators/model.rb +52 -28
- data/lib/localtower/generators/service_objects/insert_array.rb +23 -0
- data/lib/localtower/generators/service_objects/insert_defaults.rb +15 -43
- data/lib/localtower/generators/service_objects/insert_indexes.rb +80 -0
- data/lib/localtower/generators/service_objects/insert_nullable.rb +23 -0
- data/lib/localtower/status.rb +1 -1
- data/lib/localtower/tools.rb +13 -16
- data/lib/localtower/version.rb +1 -1
- data/public/css/app.css +0 -49
- data/public/js/app.js +215 -70
- data/public/screenshots/v1.0.0/migrations.png +0 -0
- data/public/screenshots/v1.0.0/models.png +0 -0
- data/public/screenshots/v1.0.0/new_migration.png +0 -0
- data/public/screenshots/v1.0.0/new_model.png +0 -0
- data/spec/dummy/Gemfile +0 -2
- data/spec/dummy/Gemfile.lock +1 -10
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +1 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/puma.rb +1 -1
- data/spec/dummy/db/migrate/20230119221452_create_users.rb +14 -0
- data/spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb +7 -0
- data/spec/dummy/db/migrate/20230119222054_create_posts.rb +11 -0
- data/spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb +5 -0
- data/spec/dummy/db/schema.rb +20 -8
- data/spec/dummy/log/development.log +15281 -3345
- data/spec/dummy/log/localtower.log +1897 -132
- data/spec/dummy/log/test.log +0 -0
- data/spec/dummy/test/index.html +38 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/factories/migration.rb +25 -41
- data/spec/factories/model.rb +39 -25
- data/spec/lib/localtower/generators/migration_spec.rb +36 -63
- data/spec/lib/localtower/generators/model_spec.rb +43 -34
- data/spec/lib/localtower/generators/service_objects/insert_array_spec.rb +47 -0
- data/spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb +30 -35
- data/spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb +90 -0
- data/spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb +61 -0
- data/spec/lib/localtower/tools_spec.rb +1 -11
- data/spec/spec_helper.rb +8 -3
- metadata +34 -18
- data/app/views/localtower/pages/_migrations.html.erb +0 -57
- data/app/views/localtower/pages/schema.html.erb +0 -67
- data/spec/dummy/db/migrate/20221115190039_create_users.rb +0 -13
- data/spec/dummy/db/migrate/20221115193020_change_users.rb +0 -8
- data/spec/dummy/db/migrate/20221115193532_change_users_at1668540931.rb +0 -5
- data/spec/dummy/db/migrate/20221115193605_change_users_at1668540964.rb +0 -5
- data/spec/dummy/db/migrate/20221115193637_change_users_at1668540996.rb +0 -5
- data/spec/dummy/db/migrate/20221115193642_change_users_at1668541001.rb +0 -5
- data/spec/lib/localtower/generators/relation_spec.rb +0 -65
@@ -2,62 +2,34 @@ module Localtower
|
|
2
2
|
module Generators
|
3
3
|
module ServiceObjects
|
4
4
|
class InsertDefaults
|
5
|
+
DEFAULTS = {
|
6
|
+
'(no default value)' => '',
|
7
|
+
"empty string ('')" => "''",
|
8
|
+
'zero (0)' => '0',
|
9
|
+
'true' => 'true',
|
10
|
+
'false' => 'false',
|
11
|
+
'empty array ([])' => '[]',
|
12
|
+
'empty hash ({})' => '{}',
|
13
|
+
'nil' => 'nil',
|
14
|
+
}
|
5
15
|
|
6
16
|
def initialize(attributes)
|
7
17
|
@attributes = attributes
|
8
18
|
end
|
9
19
|
|
10
20
|
def call
|
11
|
-
insert_defaults
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
attr_reader :attributes
|
17
|
-
|
18
|
-
def insert_defaults
|
19
21
|
attributes.each do |attribute|
|
20
22
|
attribute.each do |attr_key, attr_value|
|
21
|
-
|
23
|
+
line_str = File.read(Localtower::Tools.last_migration).match(/((.*)t\.(.*)\:#{attr_key})/)[0]
|
24
|
+
content = File.read(Localtower::Tools.last_migration).gsub(line_str, "#{line_str}, default: #{attr_value}")
|
25
|
+
File.write(Localtower::Tools.last_migration, content)
|
22
26
|
end
|
23
27
|
end
|
24
|
-
build_file(file_lines)
|
25
|
-
end
|
26
|
-
|
27
|
-
def process_migration_file(attr_key, attr_value)
|
28
|
-
file_lines.map do |line|
|
29
|
-
attach_default_value(line, attr_key, attr_value)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def attach_default_value(line, attr_key, attr_value)
|
34
|
-
if table_attribute_line?(line) and line.include? attr_key
|
35
|
-
build_line(line, attr_value)
|
36
|
-
else
|
37
|
-
line
|
38
|
-
end
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
|
-
File.open(latest_migration, 'w') { |f| f.puts lines }
|
43
|
-
end
|
44
|
-
|
45
|
-
def build_line(line, attr_value)
|
46
|
-
line.gsub!("\n", "") << ", default: " << "#{attr_value}" << "\n"
|
47
|
-
end
|
48
|
-
|
49
|
-
def latest_migration
|
50
|
-
@latest_migration ||= Dir["#{Rails.root}/db/migrate/*"].last
|
51
|
-
end
|
52
|
-
|
53
|
-
def file_lines
|
54
|
-
@file_lines ||= File.readlines(latest_migration)
|
55
|
-
end
|
56
|
-
|
57
|
-
def table_attribute_line?(line)
|
58
|
-
line.squish.start_with? "t."
|
59
|
-
end
|
30
|
+
private
|
60
31
|
|
32
|
+
attr_reader :attributes
|
61
33
|
end
|
62
34
|
end
|
63
35
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Localtower
|
2
|
+
module Generators
|
3
|
+
module ServiceObjects
|
4
|
+
class InsertIndexes
|
5
|
+
USING = [
|
6
|
+
'none',
|
7
|
+
'default',
|
8
|
+
'gin',
|
9
|
+
'gist',
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
UNIQUE = [
|
13
|
+
false,
|
14
|
+
true,
|
15
|
+
]
|
16
|
+
|
17
|
+
ALGO = [
|
18
|
+
'default',
|
19
|
+
'concurrently',
|
20
|
+
]
|
21
|
+
|
22
|
+
def initialize(attributes)
|
23
|
+
@attributes = attributes
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
attributes.each do |attribute|
|
28
|
+
attribute.each do |attr_key, options|
|
29
|
+
line_str_original = File.read(Localtower::Tools.last_migration).match(/((.*)add_index :(.*), :#{attr_key})/)[0]
|
30
|
+
line_str = line_str_original.clone
|
31
|
+
|
32
|
+
line_str = inser_using(line_str, options)
|
33
|
+
line_str = inser_unique(line_str, options)
|
34
|
+
line_str = inser_algorithm(line_str, options)
|
35
|
+
|
36
|
+
content = File.read(Localtower::Tools.last_migration).gsub(line_str_original, line_str)
|
37
|
+
content = add_disable_ddl_transaction(content, options)
|
38
|
+
|
39
|
+
File.write(Localtower::Tools.last_migration, content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :attributes
|
47
|
+
|
48
|
+
def inser_using(line_str, options)
|
49
|
+
return line_str if options['using'] == 'default'
|
50
|
+
|
51
|
+
line_str << ", using: :#{options['using']}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def inser_unique(line_str, options)
|
55
|
+
return line_str if options['unique'] != true
|
56
|
+
|
57
|
+
line_str << ", unique: true"
|
58
|
+
end
|
59
|
+
|
60
|
+
def inser_algorithm(line_str, options)
|
61
|
+
return line_str unless options['algorithm']
|
62
|
+
return line_str if options['algorithm'] == 'default'
|
63
|
+
|
64
|
+
line_str << ", algorithm: :#{options['algorithm']}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_disable_ddl_transaction(content, options)
|
68
|
+
return content if options['algorithm'] != 'concurrently'
|
69
|
+
|
70
|
+
# Add disable_ddl_transaction! if the algorythm is 'concurrently'
|
71
|
+
if content['disable_ddl_transaction'].blank?
|
72
|
+
content = content.gsub(/^class (.*)$/, "class \\1\n disable_ddl_transaction!\n")
|
73
|
+
end
|
74
|
+
|
75
|
+
content
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Localtower
|
2
|
+
module Generators
|
3
|
+
module ServiceObjects
|
4
|
+
class InsertNullable
|
5
|
+
def initialize(attributes)
|
6
|
+
@attributes = attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
attributes.each do |attribute|
|
11
|
+
line_str = File.read(Localtower::Tools.last_migration).match(/((.*)t\.(.*)\:#{attribute})/)[0]
|
12
|
+
content = File.read(Localtower::Tools.last_migration).gsub(line_str, "#{line_str}, null: false")
|
13
|
+
File.write(Localtower::Tools.last_migration, content)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :attributes
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/localtower/status.rb
CHANGED
@@ -8,7 +8,7 @@ module Localtower
|
|
8
8
|
[]
|
9
9
|
end
|
10
10
|
|
11
|
-
db_migrations = db_migrations.map { |e| e["version"].to_s }
|
11
|
+
db_migrations = db_migrations.map { |e| e["version"].to_s }
|
12
12
|
|
13
13
|
files.map do |file_full_path|
|
14
14
|
name = file_full_path.split("/")[-1] # add_email_to_user.rb
|
data/lib/localtower/tools.rb
CHANGED
@@ -135,22 +135,18 @@ module Localtower
|
|
135
135
|
end.flatten.uniq.sort
|
136
136
|
end
|
137
137
|
|
138
|
-
def perform_migration(str
|
139
|
-
self.perform_cmd("rails g migration #{str}"
|
140
|
-
|
141
|
-
if not standalone
|
142
|
-
self.perform_cmd('rake db:migrate')
|
143
|
-
end
|
138
|
+
def perform_migration(str)
|
139
|
+
self.perform_cmd("rails g migration #{str}")
|
144
140
|
end
|
145
141
|
|
146
|
-
def perform_cmd(cmd_str
|
147
|
-
self.perform_raw_cmd("bundle exec #{cmd_str}"
|
142
|
+
def perform_cmd(cmd_str)
|
143
|
+
self.perform_raw_cmd("bundle exec #{cmd_str}")
|
148
144
|
end
|
149
145
|
|
150
|
-
def perform_raw_cmd(cmd_str
|
151
|
-
root_dir
|
146
|
+
def perform_raw_cmd(cmd_str)
|
147
|
+
root_dir = ::Rails.root
|
152
148
|
|
153
|
-
cmd =
|
149
|
+
cmd = "cd \"#{root_dir}\" && #{cmd_str}"
|
154
150
|
cmd = cmd.strip
|
155
151
|
|
156
152
|
self.log("DOING...: #{cmd}")
|
@@ -174,17 +170,18 @@ module Localtower
|
|
174
170
|
end
|
175
171
|
|
176
172
|
def log_file
|
177
|
-
Rails.root.join('log', 'localtower.log')
|
173
|
+
@log_file ||= Rails.root.join('log', 'localtower.log')
|
174
|
+
end
|
175
|
+
|
176
|
+
def last_migration
|
177
|
+
Dir["#{Rails.root}/db/migrate/*.rb"].sort.last
|
178
178
|
end
|
179
179
|
|
180
180
|
# PRIVATE ==============
|
181
181
|
def create_log
|
182
182
|
return nil if File.exist?(self.log_file)
|
183
|
-
File.open(self.log_file, 'w') { |f| f.write('') }
|
184
|
-
end
|
185
183
|
|
186
|
-
|
187
|
-
File.readlines(file).grep(word_or_exp).size > 0
|
184
|
+
File.open(self.log_file, 'w') { |f| f.write('') }
|
188
185
|
end
|
189
186
|
end
|
190
187
|
end
|
data/lib/localtower/version.rb
CHANGED
data/public/css/app.css
CHANGED
@@ -1,50 +1,3 @@
|
|
1
|
-
|
2
|
-
.tower-nav{
|
3
|
-
display: none;
|
4
|
-
justify-content: space-around;
|
5
|
-
padding: 10px 0 0;
|
6
|
-
background-color: #1F77D0;
|
7
|
-
text-align: center;
|
8
|
-
}
|
9
|
-
|
10
|
-
.tower-nav div{
|
11
|
-
display: inline;
|
12
|
-
border-radius: 4px;
|
13
|
-
padding: 5px;
|
14
|
-
margin-bottom: 10px;
|
15
|
-
}
|
16
|
-
|
17
|
-
.tower-nav div:hover{
|
18
|
-
background: rgba(255, 255, 255, 0.23);
|
19
|
-
}
|
20
|
-
|
21
|
-
.tower-a{
|
22
|
-
display: inline-block;
|
23
|
-
color: white;
|
24
|
-
}
|
25
|
-
|
26
|
-
.alert {
|
27
|
-
padding: 20px 30px;
|
28
|
-
}
|
29
|
-
|
30
|
-
.tower-a:hover{
|
31
|
-
color: white;
|
32
|
-
}
|
33
|
-
|
34
|
-
.tower-nav p{
|
35
|
-
margin: 0;
|
36
|
-
line-height: 30px;
|
37
|
-
font-size: 12px;
|
38
|
-
font-weight: 600;
|
39
|
-
text-transform: uppercase;
|
40
|
-
}
|
41
|
-
|
42
|
-
@media (max-width: 991px) {
|
43
|
-
.tower-nav{
|
44
|
-
display: flex;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
1
|
.full-message {
|
49
2
|
z-index: 999;
|
50
3
|
position: fixed;
|
@@ -77,12 +30,10 @@
|
|
77
30
|
|
78
31
|
/*=========================*/
|
79
32
|
|
80
|
-
|
81
33
|
.table-condensed>tbody>tr>td, .table-condensed>tbody>tr>th, .table-condensed>tfoot>tr>td, .table-condensed>tfoot>tr>th, .table-condensed>thead>tr>td, .table-condensed>thead>tr>th {
|
82
34
|
padding: 5px;
|
83
35
|
}
|
84
36
|
|
85
|
-
|
86
37
|
.grid-sizer, .grid-item {
|
87
38
|
box-sizing: border-box;
|
88
39
|
width: 45%;
|