Guest User

Untitled

a guest
Jul 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. Index: lib/ruby/rollup_migration.rb
  2. ===================================================================
  3. --- lib/ruby/rollup_migration.rb (revision 4910)
  4. +++ lib/ruby/rollup_migration.rb (working copy)
  5. @@ -7,7 +7,7 @@
  6. metrics = metadata[:field_names] - keys
  7.  
  8. if table_exists?(sink)
  9. - fields = columns(sink).map{ |c| c.name }
  10. + fields = columns(sink).map{ |c| field_name(c.name) }
  11. missing_fields = fields - metadata[:field_names]
  12. raise "Cannot remove fields, missing: #{missing_fields.inspect}" unless missing_fields.empty?
  13.  
  14. @@ -39,18 +39,41 @@
  15. end
  16.  
  17. def self.key_column(t, name)
  18. - t.column name, column_type(name), :references => references(name)
  19. + t.column column_name(name), column_type(name), :references => references(name)
  20. end
  21.  
  22. def self.metric_column(t, name)
  23. - t.column name, column_type(name), :null => false, :default => 0, :references => references(name)
  24. + t.column column_name(name), column_type(name), :null => false, :default => 0, :references => references(name)
  25. end
  26.  
  27. + def self.column_name(name)
  28. + case name
  29. + when 'nyc_day_id' then 'nyc_day'
  30. + when 'client_day_id' then 'client_day'
  31. + when 'nyc_time_id' then 'nyc_time'
  32. + when 'client_time_id' then 'client_time'
  33. + else name
  34. + end
  35. + end
  36. +
  37. + # Inverse of column_name, TODO: refactor
  38. + def self.field_name(name)
  39. + case name
  40. + when 'nyc_day' then 'nyc_day_id'
  41. + when 'client_day' then 'client_day_id'
  42. + when 'nyc_time' then 'nyc_time_id'
  43. + when 'client_time' then 'client_time_id'
  44. + else name
  45. + end
  46. + end
  47. +
  48. # This is a hack to avoid type metadata
  49. def self.column_type(name)
  50. case name
  51. when 'match_score', 'cost', 'budget' then :float
  52. when 'match_type', 'match_algorithm' then :text
  53. + when 'nyc_day_id', 'client_day_id' then :date
  54. + when 'nyc_time_id', 'client_time_id' then :time
  55. else :integer
  56. end
  57. end
Add Comment
Please, Sign In to add comment