marty 2.5.2 → 2.5.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 +5 -5
- data/.gitignore +4 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +11 -589
- data/Gemfile +9 -9
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -3
- data/app/components/marty/api_auth_view.rb +3 -3
- data/app/components/marty/api_config_view.rb +8 -8
- data/app/components/marty/api_log_view.rb +16 -20
- data/app/components/marty/auth_app.rb +6 -6
- data/app/components/marty/base_rule_view.rb +27 -19
- data/app/components/marty/config_view.rb +12 -9
- data/app/components/marty/data_grid_view.rb +26 -26
- data/app/components/marty/delorean_rule_view.rb +0 -1
- data/app/components/marty/event_view.rb +27 -27
- data/app/components/marty/extras/layout.rb +26 -26
- data/app/components/marty/extras/misc.rb +2 -2
- data/app/components/marty/grid.rb +13 -13
- data/app/components/marty/grid_append_only.rb +0 -1
- data/app/components/marty/import_type_view.rb +13 -13
- data/app/components/marty/import_view.rb +17 -16
- data/app/components/marty/log_view.rb +16 -14
- data/app/components/marty/main_auth_app.rb +59 -59
- data/app/components/marty/main_auth_app/client/main_auth_app.js +3 -3
- data/app/components/marty/mcfly_grid_panel.rb +10 -10
- data/app/components/marty/new_posting_form.rb +11 -11
- data/app/components/marty/new_posting_window.rb +0 -1
- data/app/components/marty/posting_grid.rb +12 -13
- data/app/components/marty/promise_view.rb +6 -6
- data/app/components/marty/report_form.rb +50 -53
- data/app/components/marty/report_select.rb +27 -27
- data/app/components/marty/reporting.rb +4 -4
- data/app/components/marty/script_form.rb +40 -42
- data/app/components/marty/script_grid.rb +24 -24
- data/app/components/marty/script_tester.rb +40 -42
- data/app/components/marty/scripting.rb +25 -27
- data/app/components/marty/simple_app.rb +24 -9
- data/app/components/marty/tag_grid.rb +12 -13
- data/app/components/marty/user_view.rb +35 -35
- data/app/controllers/marty/application_controller.rb +3 -4
- data/app/controllers/marty/components_controller.rb +1 -1
- data/app/controllers/marty/delayed_job_controller.rb +1 -0
- data/app/controllers/marty/diagnostic/controller.rb +4 -6
- data/app/controllers/marty/job_controller.rb +6 -6
- data/app/controllers/marty/report_controller.rb +11 -11
- data/app/controllers/marty/rpc_controller.rb +15 -16
- data/app/helpers/marty/script_set.rb +4 -4
- data/app/models/marty/api_auth.rb +4 -5
- data/app/models/marty/api_config.rb +1 -1
- data/app/models/marty/base.rb +9 -8
- data/app/models/marty/base_rule.rb +18 -13
- data/app/models/marty/config.rb +4 -5
- data/app/models/marty/data_grid.rb +157 -181
- data/app/models/marty/delorean_rule.rb +63 -62
- data/app/models/marty/enum.rb +1 -1
- data/app/models/marty/event.rb +56 -59
- data/app/models/marty/helper.rb +38 -6
- data/app/models/marty/import_type.rb +6 -6
- data/app/models/marty/log.rb +3 -2
- data/app/models/marty/name_validator.rb +3 -2
- data/app/models/marty/pg_enum.rb +3 -4
- data/app/models/marty/posting.rb +20 -24
- data/app/models/marty/promise.rb +28 -30
- data/app/models/marty/script.rb +30 -28
- data/app/models/marty/tag.rb +8 -8
- data/app/models/marty/token.rb +2 -2
- data/app/models/marty/user.rb +24 -23
- data/app/models/marty/vw_promise.rb +10 -11
- data/config/routes.rb +2 -2
- data/delorean/blame_report.dl +268 -0
- data/{spec/dummy/delorean/fields.dl → delorean/marty_fields.dl} +8 -0
- data/delorean/table_report.dl +34 -0
- data/docker-compose.dummy.yml +2 -3
- data/lib/marty/aws/base.rb +8 -8
- data/lib/marty/aws/request.rb +4 -4
- data/lib/marty/cache_adapters/mcfly_ruby_cache.rb +1 -0
- data/lib/marty/content_handler.rb +25 -25
- data/lib/marty/data_change.rb +49 -71
- data/lib/marty/data_conversion.rb +20 -28
- data/lib/marty/data_exporter.rb +25 -28
- data/lib/marty/data_importer.rb +25 -27
- data/lib/marty/engine.rb +1 -2
- data/lib/marty/json_schema.rb +22 -24
- data/lib/marty/logger.rb +6 -9
- data/lib/marty/mcfly_model.rb +20 -24
- data/lib/marty/migrations.rb +37 -35
- data/lib/marty/monkey.rb +33 -33
- data/lib/marty/permissions.rb +18 -18
- data/lib/marty/promise_job.rb +17 -17
- data/lib/marty/promise_proxy.rb +6 -6
- data/lib/marty/relation.rb +6 -7
- data/lib/marty/rpc_call.rb +13 -12
- data/lib/marty/rule_script_set.rb +32 -28
- data/lib/marty/schema_helper.rb +37 -51
- data/lib/marty/util.rb +25 -24
- data/lib/marty/version.rb +1 -1
- data/lib/marty/xl.rb +121 -115
- data/make-dummy.mk +3 -0
- data/marty.gemspec +21 -21
- data/other/marty/api/base.rb +34 -35
- data/other/marty/diagnostic/aws/ec2_instance.rb +8 -8
- data/other/marty/diagnostic/base.rb +13 -14
- data/other/marty/diagnostic/collection.rb +2 -1
- data/other/marty/diagnostic/connections.rb +8 -6
- data/other/marty/diagnostic/database.rb +1 -0
- data/other/marty/diagnostic/delayed_job_version.rb +7 -9
- data/other/marty/diagnostic/delayed_job_worker_total_count.rb +1 -1
- data/other/marty/diagnostic/delayed_job_workers.rb +1 -1
- data/other/marty/diagnostic/environment_variables.rb +17 -15
- data/other/marty/diagnostic/fatal.rb +1 -1
- data/other/marty/diagnostic/node.rb +5 -9
- data/other/marty/diagnostic/nodes.rb +7 -5
- data/other/marty/diagnostic/packer.rb +7 -7
- data/other/marty/diagnostic/reporter.rb +24 -27
- data/other/marty/diagnostic/version.rb +3 -5
- data/script/rails +2 -1
- data/spec/controllers/application_controller_spec.rb +6 -6
- data/spec/controllers/delayed_job_controller_spec.rb +4 -4
- data/spec/controllers/diagnostic/controller_spec.rb +59 -60
- data/spec/controllers/job_controller_spec.rb +68 -69
- data/spec/controllers/rpc_controller_spec.rb +353 -359
- data/spec/controllers/rpc_import_spec.rb +15 -16
- data/spec/dummy/delorean/blame_report.dl +110 -15
- data/spec/dummy/delorean/data_report.dl +4 -4
- data/spec/dummy/delorean/marty_fields.dl +63 -0
- data/spec/dummy/delorean/table_report.dl +34 -0
- data/spec/features/auth_app_spec.rb +1 -2
- data/spec/features/data_import_spec.rb +2 -3
- data/spec/features/enum_spec.rb +42 -46
- data/spec/features/jobs_dashboard_spec.rb +14 -8
- data/spec/features/log_view_spec.rb +40 -43
- data/spec/features/reporting_spec.rb +15 -15
- data/spec/features/rule_spec.rb +195 -190
- data/spec/features/scripting_spec.rb +17 -20
- data/spec/features/scripting_test_spec.rb +32 -33
- data/spec/features/user_view_spec.rb +15 -17
- data/spec/job_helper.rb +11 -11
- data/spec/lib/data_blame_spec.rb +82 -0
- data/spec/lib/data_exporter_spec.rb +31 -32
- data/spec/lib/data_importer_spec.rb +382 -395
- data/spec/lib/delorean_query_spec.rb +117 -119
- data/spec/lib/json_schema_spec.rb +382 -392
- data/spec/lib/logger_spec.rb +23 -24
- data/spec/lib/mcfly_model_spec.rb +112 -109
- data/spec/lib/migrations_spec.rb +10 -10
- data/spec/lib/struct_compare_spec.rb +6 -6
- data/spec/lib/table_report_spec.rb +90 -0
- data/spec/lib/xl_spec.rb +63 -65
- data/spec/lib/xl_styles_spec.rb +16 -19
- data/spec/models/api_auth_spec.rb +30 -30
- data/spec/models/config_spec.rb +32 -32
- data/spec/models/data_grid_spec.rb +642 -655
- data/spec/models/event_spec.rb +96 -88
- data/spec/models/import_type_spec.rb +20 -20
- data/spec/models/posting_spec.rb +35 -35
- data/spec/models/promise_spec.rb +5 -5
- data/spec/models/rule_spec.rb +280 -269
- data/spec/models/script_spec.rb +27 -18
- data/spec/models/user_spec.rb +9 -9
- data/spec/other/diagnostic/base_spec.rb +20 -19
- data/spec/other/diagnostic/collection_spec.rb +6 -5
- data/spec/other/diagnostic/delayed_job_version_spec.rb +1 -1
- data/spec/other/diagnostic/delayed_job_workers_spec.rb +8 -8
- data/spec/other/diagnostic/reporter_spec.rb +31 -33
- data/spec/spec_helper.rb +5 -5
- data/spec/support/chromedriver.rb +3 -5
- data/spec/support/components/netzke_combobox.rb +1 -1
- data/spec/support/components/netzke_grid.rb +17 -17
- data/spec/support/custom_matchers.rb +2 -2
- data/spec/support/download_helper.rb +1 -1
- data/spec/support/helper.rb +1 -2
- data/spec/support/netzke.rb +31 -31
- data/spec/support/performance_helper.rb +8 -8
- data/spec/support/post_run_logger.rb +1 -2
- data/spec/support/setup.rb +1 -4
- data/spec/support/shared_connection.rb +2 -2
- data/spec/support/structure_compare.rb +21 -22
- data/spec/support/suite.rb +1 -2
- data/spec/support/users.rb +5 -6
- metadata +32 -26
data/lib/marty/logger.rb
CHANGED
|
@@ -4,27 +4,24 @@ class Marty::Logger
|
|
|
4
4
|
def self.method_missing(m, *args, &block)
|
|
5
5
|
return super unless
|
|
6
6
|
[:debug, :info, :warn, :error, :fatal, :unknown].include?(m)
|
|
7
|
+
|
|
7
8
|
Marty::Util.logger.send(m, args[0]) if Marty::Util.logger.respond_to?(m)
|
|
8
9
|
log(m, *args)
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
def self.log(type, message, details=nil)
|
|
12
|
+
def self.log(type, message, details = nil)
|
|
12
13
|
Marty::Log.write_log(type, message, details)
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def self.with_logging(error_message, error_data)
|
|
16
|
-
begin
|
|
17
17
|
yield
|
|
18
|
-
|
|
19
|
-
error(error_message,
|
|
20
|
-
|
|
18
|
+
rescue StandardError => e
|
|
19
|
+
error(error_message, 'message' => e.message,
|
|
20
|
+
'data' => error_data)
|
|
21
21
|
raise "#{error_message}: #{e.message}"
|
|
22
|
-
end
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
delorean_fn :dllog, sig: [2, 20] do
|
|
26
|
-
|*args|
|
|
27
|
-
|
|
24
|
+
delorean_fn :dllog, sig: [2, 20] do |*args|
|
|
28
25
|
info args[0], args[1..-1]
|
|
29
26
|
end
|
|
30
27
|
end
|
data/lib/marty/mcfly_model.rb
CHANGED
|
@@ -11,14 +11,13 @@ module Mcfly::Model
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def base_mcfly_lookup(meth, name, options = {}, &block)
|
|
14
|
-
|
|
15
14
|
priv = options[:private]
|
|
16
15
|
|
|
17
16
|
send(meth, name, options) do |ts, *args|
|
|
18
|
-
raise
|
|
17
|
+
raise 'time cannot be nil' if ts.nil?
|
|
19
18
|
|
|
20
19
|
ts = Mcfly.normalize_infinity(ts)
|
|
21
|
-
q =
|
|
20
|
+
q = where("#{table_name}.obsoleted_dt >= ? AND " +
|
|
22
21
|
"#{table_name}.created_dt < ?", ts, ts).scoping do
|
|
23
22
|
block.call(ts, *args)
|
|
24
23
|
end
|
|
@@ -40,7 +39,7 @@ module Mcfly::Model
|
|
|
40
39
|
base_mcfly_lookup(:delorean_fn, name, options, &block)
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
def gen_mcfly_lookup(name, attrs, options={})
|
|
42
|
+
def gen_mcfly_lookup(name, attrs, options = {})
|
|
44
43
|
raise "bad options #{options.keys}" unless
|
|
45
44
|
(options.keys - [:mode, :cache, :private]).empty?
|
|
46
45
|
|
|
@@ -52,36 +51,35 @@ module Mcfly::Model
|
|
|
52
51
|
# the older mode=:all is not supported (it's bogus)
|
|
53
52
|
raise "bad mode #{mode}" unless [nil, :first].member?(mode)
|
|
54
53
|
|
|
55
|
-
assoc = Set.new(
|
|
54
|
+
assoc = Set.new(reflect_on_all_associations.map(&:name))
|
|
56
55
|
|
|
57
|
-
qstr = attrs.map
|
|
56
|
+
qstr = attrs.map do |k, v|
|
|
58
57
|
k = "#{k}_id" if assoc.member?(k)
|
|
59
58
|
|
|
60
59
|
v ? "(#{k} = ? OR #{k} IS NULL)" : "(#{k} = ?)"
|
|
61
|
-
|
|
60
|
+
end.join(' AND ')
|
|
62
61
|
|
|
63
62
|
if Hash === attrs
|
|
64
|
-
order = attrs.select {|k, v| v}.keys.reverse.map
|
|
63
|
+
order = attrs.select { |k, v| v }.keys.reverse.map do |k|
|
|
65
64
|
k = "#{k}_id" if assoc.member?(k)
|
|
66
65
|
|
|
67
66
|
"#{k} NULLS LAST"
|
|
68
|
-
|
|
67
|
+
end.join(', ')
|
|
69
68
|
attrs = attrs.keys
|
|
70
69
|
else
|
|
71
|
-
raise
|
|
70
|
+
raise 'bad attrs' unless Array === attrs
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
fn = cache ? :cached_delorean_fn : :delorean_fn
|
|
75
|
-
base_mcfly_lookup(fn, name, options + {sig: attrs.length+1,
|
|
76
|
-
mode: mode}) do
|
|
77
|
-
|t, *attr_list|
|
|
74
|
+
base_mcfly_lookup(fn, name, options + { sig: attrs.length + 1,
|
|
75
|
+
mode: mode }) do |t, *attr_list|
|
|
78
76
|
|
|
79
|
-
attr_list_ids = attr_list.each_with_index.map
|
|
77
|
+
attr_list_ids = attr_list.each_with_index.map do |x, i|
|
|
80
78
|
assoc.member?(attrs[i]) ?
|
|
81
79
|
(attr_list[i] && attr_list[i].id) : attr_list[i]
|
|
82
|
-
|
|
80
|
+
end
|
|
83
81
|
|
|
84
|
-
q =
|
|
82
|
+
q = where(qstr, *attr_list_ids)
|
|
85
83
|
q = q.order(order) if order
|
|
86
84
|
q
|
|
87
85
|
end
|
|
@@ -109,7 +107,7 @@ module Mcfly::Model
|
|
|
109
107
|
# pc_name = :pc_lookup_q
|
|
110
108
|
# pc_attrs = {entity: true, security_instrument: true, coupon: true}
|
|
111
109
|
|
|
112
|
-
def gen_mcfly_lookup_cat(name, catrel, attrs, options={})
|
|
110
|
+
def gen_mcfly_lookup_cat(name, catrel, attrs, options = {})
|
|
113
111
|
rel_attr, cat_assoc_name, cat_attr = catrel
|
|
114
112
|
|
|
115
113
|
raise "#{rel_attr} should be mapped in attrs" if attrs[rel_attr].nil?
|
|
@@ -118,13 +116,13 @@ module Mcfly::Model
|
|
|
118
116
|
cat_attr_id = "#{cat_attr}_id"
|
|
119
117
|
|
|
120
118
|
# replace rel_attr with cat_attr in attrs
|
|
121
|
-
pc_attrs = attrs.each_with_object({})
|
|
119
|
+
pc_attrs = attrs.each_with_object({}) do |(k, v), h|
|
|
122
120
|
h[k == rel_attr ? cat_attr_id : k] = v
|
|
123
|
-
|
|
121
|
+
end
|
|
124
122
|
|
|
125
123
|
pc_name = "pc_#{name}".to_sym
|
|
126
124
|
|
|
127
|
-
gen_mcfly_lookup(pc_name, pc_attrs, options + {private: true})
|
|
125
|
+
gen_mcfly_lookup(pc_name, pc_attrs, options + { private: true })
|
|
128
126
|
|
|
129
127
|
lpi = attrs.keys.index rel_attr
|
|
130
128
|
|
|
@@ -135,9 +133,7 @@ module Mcfly::Model
|
|
|
135
133
|
fn = options.fetch(:mode, :first) ? :cached_delorean_fn : :delorean_fn
|
|
136
134
|
priv = options[:private]
|
|
137
135
|
|
|
138
|
-
send(fn, name, sig: attrs.length+1) do
|
|
139
|
-
|ts, *args|
|
|
140
|
-
|
|
136
|
+
send(fn, name, sig: attrs.length + 1) do |ts, *args|
|
|
141
137
|
# Example: rel is a Gemini::SecurityInstrument instance.
|
|
142
138
|
rel = args[lpi]
|
|
143
139
|
raise "#{rel_attr} can't be nil" unless rel
|
|
@@ -148,7 +144,7 @@ module Mcfly::Model
|
|
|
148
144
|
find_by(rel_attr => rel).
|
|
149
145
|
send(cat_attr_id)
|
|
150
146
|
|
|
151
|
-
q =
|
|
147
|
+
q = send(pc_name, ts, *args)
|
|
152
148
|
hash_if_necessary(q, priv)
|
|
153
149
|
end
|
|
154
150
|
end
|
data/lib/marty/migrations.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
module Marty::Migrations
|
|
2
2
|
def tb_prefix
|
|
3
|
-
|
|
3
|
+
'marty_'
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def new_enum(klass, prefix_override = nil)
|
|
7
7
|
raise "bad class arg #{klass}" unless
|
|
8
8
|
klass.is_a?(Class) && klass < ActiveRecord::Base
|
|
9
9
|
|
|
10
|
-
raise
|
|
10
|
+
raise 'model class needs VALUES (as Set)' unless
|
|
11
11
|
klass.const_defined?(:VALUES)
|
|
12
12
|
|
|
13
13
|
values = klass::VALUES
|
|
14
14
|
str_values =
|
|
15
|
-
values.map {|v| ActiveRecord::Base.connection.quote v}.join ','
|
|
15
|
+
values.map { |v| ActiveRecord::Base.connection.quote v }.join ','
|
|
16
16
|
|
|
17
|
-
#hacky way to get name
|
|
17
|
+
# hacky way to get name
|
|
18
18
|
prefix = prefix_override || tb_prefix
|
|
19
19
|
enum_name = klass.table_name.sub(/^#{prefix}_*/, '')
|
|
20
20
|
|
|
@@ -28,14 +28,14 @@ module Marty::Migrations
|
|
|
28
28
|
raise "bad class arg #{klass}" unless
|
|
29
29
|
klass.is_a?(Class) && klass < ActiveRecord::Base
|
|
30
30
|
|
|
31
|
-
raise
|
|
31
|
+
raise 'model class needs VALUES (as Set)' unless
|
|
32
32
|
klass.const_defined?(:VALUES)
|
|
33
33
|
|
|
34
|
-
#hacky way to get name
|
|
34
|
+
# hacky way to get name
|
|
35
35
|
prefix = prefix_override || tb_prefix
|
|
36
36
|
enum_name = klass.table_name.sub(/^#{prefix}/, '')
|
|
37
37
|
|
|
38
|
-
#check values against underlying values
|
|
38
|
+
# check values against underlying values
|
|
39
39
|
res = execute <<-SQL
|
|
40
40
|
SELECT ENUM_RANGE(null::#{enum_name});
|
|
41
41
|
SQL
|
|
@@ -63,7 +63,7 @@ module Marty::Migrations
|
|
|
63
63
|
# FIXME: so hacky to specifically check for "marty_"
|
|
64
64
|
to_table = "#{tb_prefix}#{to_table}" unless
|
|
65
65
|
to_table.to_s.start_with?(tb_prefix) ||
|
|
66
|
-
to_table.to_s.start_with?(
|
|
66
|
+
to_table.to_s.start_with?('marty_')
|
|
67
67
|
|
|
68
68
|
add_foreign_key(from_table,
|
|
69
69
|
to_table,
|
|
@@ -86,9 +86,9 @@ module Marty::Migrations
|
|
|
86
86
|
|
|
87
87
|
add_mcfly_attrs_index(tb, *attrs)
|
|
88
88
|
|
|
89
|
-
MCFLY_INDEX_COLUMNS.each
|
|
89
|
+
MCFLY_INDEX_COLUMNS.each do |a|
|
|
90
90
|
add_index tb.to_sym, a, index_opts(tb, a)
|
|
91
|
-
|
|
91
|
+
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
def add_mcfly_unique_index(klass)
|
|
@@ -115,19 +115,19 @@ module Marty::Migrations
|
|
|
115
115
|
|
|
116
116
|
remove_index(klass.table_name.to_sym,
|
|
117
117
|
name: unique_index_name(klass)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
) if index_exists?(klass.table_name.to_sym,
|
|
119
|
+
attrs,
|
|
120
|
+
name: unique_index_name(klass),
|
|
121
|
+
unique: true)
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
def self.write_view(target_dir, target_view, klass, jsons, excludes, extras)
|
|
125
125
|
colnames = klass.columns_hash.keys
|
|
126
|
-
excludes += [
|
|
127
|
-
joins = [
|
|
128
|
-
|
|
129
|
-
columns = [
|
|
130
|
-
|
|
126
|
+
excludes += ['user_id', 'o_user_id']
|
|
127
|
+
joins = ['join marty_users u on main.user_id = u.id',
|
|
128
|
+
'left join marty_users ou on main.o_user_id = ou.id']
|
|
129
|
+
columns = ['u.login AS user_name',
|
|
130
|
+
'ou.login AS obsoleted_user']
|
|
131
131
|
jointabs = {}
|
|
132
132
|
colnames.each do |c|
|
|
133
133
|
if jsons[c]
|
|
@@ -142,14 +142,14 @@ module Marty::Migrations
|
|
|
142
142
|
end
|
|
143
143
|
elsif !excludes.include?(c)
|
|
144
144
|
assoc = klass.reflections.find { |(n, h)| h.foreign_key == c }
|
|
145
|
-
if assoc && assoc[1].klass.columns_hash[
|
|
145
|
+
if assoc && assoc[1].klass.columns_hash['name']
|
|
146
146
|
table_name = assoc[1].table_name
|
|
147
147
|
jointabs[table_name] ||= 0
|
|
148
148
|
jointabs[table_name] += 1
|
|
149
149
|
tn_alias = "#{table_name}#{jointabs[table_name]}"
|
|
150
150
|
joins.push "left join #{table_name} #{tn_alias} on main.#{c} " +
|
|
151
151
|
"= #{tn_alias}.id"
|
|
152
|
-
target_name = c.gsub(/_id$/,'_name')
|
|
152
|
+
target_name = c.gsub(/_id$/, '_name')
|
|
153
153
|
columns.push "#{tn_alias}.name as #{target_name}"
|
|
154
154
|
extras.each do |(table, column, new_colname)|
|
|
155
155
|
columns.push "#{tn_alias}.#{column} as #{new_colname}" if
|
|
@@ -160,7 +160,7 @@ module Marty::Migrations
|
|
|
160
160
|
end
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
|
-
File.open(File.join(target_dir, "#{target_view}.sql"),
|
|
163
|
+
File.open(File.join(target_dir, "#{target_view}.sql"), 'w') do |f|
|
|
164
164
|
f.puts <<EOSQL
|
|
165
165
|
create or replace function f_fixfalse(s text) returns text as $$
|
|
166
166
|
begin
|
|
@@ -205,14 +205,14 @@ EOSQL
|
|
|
205
205
|
gen_count = 0
|
|
206
206
|
|
|
207
207
|
sql_files.each do |sql|
|
|
208
|
-
base = File.basename(sql,
|
|
208
|
+
base = File.basename(sql, '.sql')
|
|
209
209
|
existing = mig_files[base].first rescue nil
|
|
210
210
|
# must ensure CRLF line endings or SQL Server keep asking about line
|
|
211
211
|
# endings whenever you generating script
|
|
212
|
-
sql_lines = lines_to_crlf(File.open(sql,
|
|
212
|
+
sql_lines = lines_to_crlf(File.open(sql, 'r').readlines)
|
|
213
213
|
next if existing && sql_lines == File.open(existing[:raw_sql]).readlines
|
|
214
214
|
|
|
215
|
-
timestamp = (time_now + gen_count.seconds).strftime(
|
|
215
|
+
timestamp = (time_now + gen_count.seconds).strftime('%Y%m%d%H%M%S')
|
|
216
216
|
v = existing && existing[:version] + 1 || 1
|
|
217
217
|
klass = "v#{v}_sql_#{base}"
|
|
218
218
|
newbase = "#{timestamp}_#{klass}"
|
|
@@ -221,14 +221,14 @@ EOSQL
|
|
|
221
221
|
sql_snap_call =
|
|
222
222
|
"Rails.root.join('#{migrations_dir}', 'sql', '#{newbase}.sql')"
|
|
223
223
|
|
|
224
|
-
File.open(sql_snap_literal,
|
|
224
|
+
File.open(sql_snap_literal, 'w') do |f|
|
|
225
225
|
f.print sql_lines.join
|
|
226
226
|
end
|
|
227
227
|
puts "creating #{newbase}.rb"
|
|
228
228
|
|
|
229
229
|
# only split on "GO" at the start of a line with optional whitespace
|
|
230
230
|
# before EOL. GO in comments could trigger this and will cause an error
|
|
231
|
-
File.open(mig_name,
|
|
231
|
+
File.open(mig_name, 'w') do |f|
|
|
232
232
|
f.print <<OUT
|
|
233
233
|
class #{klass.camelcase} < ActiveRecord::Migration[4.2]
|
|
234
234
|
|
|
@@ -254,20 +254,21 @@ OUT
|
|
|
254
254
|
# we have to get it from the database
|
|
255
255
|
def get_old_enum_id(klass, name)
|
|
256
256
|
ActiveRecord::Base.
|
|
257
|
-
connection.execute(<<-SQL).to_a.first.try{|v| v['id']}
|
|
257
|
+
connection.execute(<<-SQL).to_a.first.try { |v| v['id'] }
|
|
258
258
|
select id from #{klass.table_name} where name =
|
|
259
259
|
#{ActiveRecord::Base.connection.quote(name)}
|
|
260
260
|
SQL
|
|
261
261
|
end
|
|
262
262
|
|
|
263
263
|
private
|
|
264
|
+
|
|
264
265
|
def fk_opts(from, to, column)
|
|
265
266
|
name = "fk_#{from}_#{to}_#{column}"
|
|
266
267
|
if name.length > 63
|
|
267
268
|
s = Digest::MD5.hexdigest("#{to}_#{column}").slice(0..9)
|
|
268
269
|
name = "fk_#{from}_#{s}"
|
|
269
270
|
end
|
|
270
|
-
{name: name}
|
|
271
|
+
{ name: name }
|
|
271
272
|
end
|
|
272
273
|
|
|
273
274
|
def index_opts(tb, a)
|
|
@@ -278,11 +279,11 @@ OUT
|
|
|
278
279
|
end
|
|
279
280
|
|
|
280
281
|
def add_mcfly_attrs_index(tb, *attrs)
|
|
281
|
-
attrs.each
|
|
282
|
+
attrs.each do |a|
|
|
282
283
|
options = index_opts(tb, a)
|
|
283
|
-
options[:order] = {a.to_sym =>
|
|
284
|
+
options[:order] = { a.to_sym => 'NULLS LAST' }
|
|
284
285
|
add_index tb.to_sym, a, options
|
|
285
|
-
|
|
286
|
+
end
|
|
286
287
|
end
|
|
287
288
|
|
|
288
289
|
def unique_index_name(klass)
|
|
@@ -305,15 +306,16 @@ OUT
|
|
|
305
306
|
|
|
306
307
|
def self.get_plv8_migration(file)
|
|
307
308
|
fnname = %r(/([^/]+)_v[0-9]+\.js\z).match(file)[1]
|
|
308
|
-
lines=File.readlines(file)
|
|
309
|
+
lines = File.readlines(file)
|
|
309
310
|
parts = lines.map do |line|
|
|
310
311
|
next [:param, $1] if %r(\A// PARAM[:] (.*)$).match(line)
|
|
311
312
|
next [:ret, $1] if %r(\A// RETURN[:] (.*)$).match(line)
|
|
313
|
+
|
|
312
314
|
[:body, line]
|
|
313
315
|
end.group_by(&:first)
|
|
314
|
-
args = parts[:param].map{ |(_,l)| l}.join(",\n")
|
|
316
|
+
args = parts[:param].map { |(_, l)| l }.join(",\n")
|
|
315
317
|
ret = parts[:ret][0][1]
|
|
316
|
-
body = parts[:body].map{ |(_,l)| l}.join
|
|
318
|
+
body = parts[:body].map { |(_, l)| l }.join
|
|
317
319
|
<<EOT
|
|
318
320
|
CREATE OR REPLACE FUNCTION #{fnname} (
|
|
319
321
|
#{args}
|
data/lib/marty/monkey.rb
CHANGED
|
@@ -25,14 +25,14 @@ end
|
|
|
25
25
|
class Hash
|
|
26
26
|
# define addition on hashes -- useful in Delorean code.
|
|
27
27
|
def +(x)
|
|
28
|
-
|
|
28
|
+
merge(x)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# define hash slice (similar to node slice in Delorean)
|
|
32
32
|
def %(x)
|
|
33
|
-
x.each_with_object({})
|
|
33
|
+
x.each_with_object({}) do |k, h|
|
|
34
34
|
h[k] = self[k]
|
|
35
|
-
|
|
35
|
+
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ require 'netzke-basepack'
|
|
|
42
42
|
|
|
43
43
|
class Netzke::Base
|
|
44
44
|
# get root component session
|
|
45
|
-
def root_sess(component=nil)
|
|
45
|
+
def root_sess(component = nil)
|
|
46
46
|
component ||= self
|
|
47
47
|
component.parent ? root_sess(component.parent) : component.component_session
|
|
48
48
|
end
|
|
@@ -87,7 +87,6 @@ class String
|
|
|
87
87
|
def in_time_zone(zone = ::Time.zone)
|
|
88
88
|
self == 'infinity' ? self : old_in_time_zone(zone)
|
|
89
89
|
end
|
|
90
|
-
|
|
91
90
|
end
|
|
92
91
|
|
|
93
92
|
######################################################################
|
|
@@ -121,8 +120,8 @@ module Netzke::Basepack::DataAdapters
|
|
|
121
120
|
arel_table = assoc ? Arel::Table.new(assoc.klass.table_name.to_sym) :
|
|
122
121
|
@model.arel_table
|
|
123
122
|
|
|
124
|
-
value = q[
|
|
125
|
-
op = q[
|
|
123
|
+
value = q['value']
|
|
124
|
+
op = q['operator']
|
|
126
125
|
|
|
127
126
|
attr_type = attr_type(attr)
|
|
128
127
|
|
|
@@ -144,11 +143,11 @@ module Netzke::Basepack::DataAdapters
|
|
|
144
143
|
end
|
|
145
144
|
|
|
146
145
|
# join them by AND
|
|
147
|
-
predicates[1..-1].inject(predicates.first){ |r,p| r.and(p) }
|
|
146
|
+
predicates[1..-1].inject(predicates.first) { |r, p| r.and(p) }
|
|
148
147
|
end
|
|
149
148
|
|
|
150
149
|
def update_predecate_for_enum(table, op, value)
|
|
151
|
-
col = Arel::Nodes::NamedFunction.new(
|
|
150
|
+
col = Arel::Nodes::NamedFunction.new('CAST', [table.as('TEXT')])
|
|
152
151
|
col.matches "%#{value}%"
|
|
153
152
|
end
|
|
154
153
|
end
|
|
@@ -166,8 +165,9 @@ module ActiveRecord
|
|
|
166
165
|
|
|
167
166
|
enum = options.delete(:enum)
|
|
168
167
|
|
|
169
|
-
column_names.each
|
|
170
|
-
column(name, enum || name.to_s.pluralize, options)
|
|
168
|
+
column_names.each do |name|
|
|
169
|
+
column(name, enum || name.to_s.pluralize, options)
|
|
170
|
+
end
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
end
|
|
@@ -176,10 +176,10 @@ end
|
|
|
176
176
|
######################################################################
|
|
177
177
|
|
|
178
178
|
class ActiveRecord::Relation
|
|
179
|
-
def mcfly_pt(pt, cls=nil)
|
|
180
|
-
cls ||=
|
|
179
|
+
def mcfly_pt(pt, cls = nil)
|
|
180
|
+
cls ||= klass
|
|
181
181
|
tb = cls.table_name
|
|
182
|
-
|
|
182
|
+
where("#{tb}.obsoleted_dt >= ? AND #{tb}.created_dt < ?", pt, pt)
|
|
183
183
|
end
|
|
184
184
|
|
|
185
185
|
def attributes
|
|
@@ -216,9 +216,9 @@ class ActiveRecord::Base
|
|
|
216
216
|
# when joins args are strings, checks to see if they're
|
|
217
217
|
# associations attrs. If so, convert them to symbols for joins
|
|
218
218
|
# to work properly.
|
|
219
|
-
new_args = args.map
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
new_args = args.map do |a|
|
|
220
|
+
reflections.key?(a) ? a.to_sym : a
|
|
221
|
+
end
|
|
222
222
|
old_joins(*new_args)
|
|
223
223
|
end
|
|
224
224
|
end
|
|
@@ -226,19 +226,20 @@ end
|
|
|
226
226
|
|
|
227
227
|
ar_instances = [ActiveRecord::Relation, ActiveRecord::QueryMethods::WhereChain]
|
|
228
228
|
|
|
229
|
-
args_hack = [[Object, nil]]*10
|
|
230
|
-
|
|
231
|
-
[
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
229
|
+
args_hack = [[Object, nil]] * 10
|
|
230
|
+
|
|
231
|
+
[
|
|
232
|
+
[:distinct, args_hack],
|
|
233
|
+
[:find_by, args_hack],
|
|
234
|
+
[:group, args_hack],
|
|
235
|
+
[:joins, args_hack],
|
|
236
|
+
[:limit, [Integer]],
|
|
237
|
+
[:not, args_hack],
|
|
238
|
+
[:order, args_hack],
|
|
239
|
+
[:pluck, args_hack],
|
|
240
|
+
[:select, args_hack],
|
|
241
|
+
[:where, args_hack],
|
|
242
|
+
[:mcfly_pt, [[Date, Time, ActiveSupport::TimeWithZone, String], [nil, Class]]]
|
|
242
243
|
].each do |meth, args|
|
|
243
244
|
::Delorean::Ruby.whitelist.add_method meth do |method|
|
|
244
245
|
ar_instances.each do |ar|
|
|
@@ -254,10 +255,9 @@ end
|
|
|
254
255
|
::Delorean::Ruby.whitelist.add_method :lookup_grid_distinct_entry do |method|
|
|
255
256
|
method.called_on OpenStruct, with: [[Date, Time,
|
|
256
257
|
ActiveSupport::TimeWithZone, String],
|
|
257
|
-
|
|
258
|
+
Hash]
|
|
258
259
|
end
|
|
259
260
|
|
|
260
|
-
|
|
261
261
|
mcfly_cache_adapter = ::Marty::CacheAdapters::McflyRubyCache.new(
|
|
262
262
|
size_per_class: 1000
|
|
263
263
|
)
|
|
@@ -278,7 +278,7 @@ end
|
|
|
278
278
|
class OpenStruct
|
|
279
279
|
# the default as_json produces {"table"=>h} which is quite goofy
|
|
280
280
|
def as_json(*)
|
|
281
|
-
|
|
281
|
+
to_h
|
|
282
282
|
end
|
|
283
283
|
end
|
|
284
284
|
|