eve_app 0.1.11 → 0.1.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02ea6c1e6b9b6c9e9ff7652d6735a3abb2df0a72
4
- data.tar.gz: eaaae3b38e6384eb6c21a415fbb299e52ffead38
3
+ metadata.gz: 57c8d8f59f960e2c00cda4ce2ba5ba8c2e268e40
4
+ data.tar.gz: 15af8961dd8c713c389613226ae81ef2eb927fd3
5
5
  SHA512:
6
- metadata.gz: ac2803e27660b03ff755a49652690f2042eac8eba469d6485cf5b3569e6b232bc281699cd7fb0eb5573810239117c2a0a03f9ae46a7012ca9e5748a4e3477c14
7
- data.tar.gz: 5502bb2b4a8d1950d8a607fbc274db79884fe3a3813aa7c4e4aa64b2bcde64a9d7d6429d67a45bc643e71f7808790c6557d497dd47c2f8b66fcef56685a42064
6
+ metadata.gz: 6d9c36fa6a1326997245fe2bef3fe35a9d3c189a32ce4f91fe040c08d07885f6988ecc8850c67e4a7b0df39f2df545cf8335c12f92023bbc2df4f30f8f762da8
7
+ data.tar.gz: 9c04bdcf42755174e84b5de11ec79c4b4a57ae2f407b52e3b132ba50f246ddaad1d40891e4ceeb74195ce26ff8b33a9ad1b3f3559f2e14abb390336b0a4bd74b
@@ -3,7 +3,9 @@ class EveApp::ActivityMaterial < EveApp::ApplicationRecord
3
3
 
4
4
  belongs_to :material_type, class_name: 'EveApp::Type', foreign_key: :material_type_id
5
5
 
6
- scope :order_by_quantity, -> { order(quantity: :desc) }
6
+ scope :buildable, -> { joins(:material_type).where.not(eve_types: { blueprint_type_id: nil }) }
7
+ scope :simple, -> { joins(:material_type).where(eve_types: { blueprint_type_id: nil }) }
8
+ # scope :order_by_quantity, -> { order(quantity: :desc) }
7
9
 
8
10
  def quantity_for(runs)
9
11
  runs > 0 ? runs * quantity : 0
@@ -29,12 +29,18 @@ module EveApp
29
29
  def table_list
30
30
  @_table_list ||= begin
31
31
  whitelist = Array[SDE.config.table_whitelist].flatten.compact.map(&:to_s)
32
- tables = SDE.table_list
33
- tables = whitelist.any? ? tables & whitelist : tables
34
- Hash[tables.map { |name| [name, normalize_table_name(name)] }]
32
+ tables = SDE.table_info
33
+ tables.transform_values!(&:symbolize_keys)
34
+ tables.select! { |(name,_)| whitelist.include?(name) } if whitelist.any?
35
+
36
+ Hash[tables.map { |(name,info)| [name, { name: normalize_table_name(name) }.merge(info)] }]
35
37
  end
36
38
  end
37
39
 
40
+ def table_names
41
+ Hash[table_list.map { |(on,info)| [on, info[:name]] }]
42
+ end
43
+
38
44
  def normalize_table_name(name)
39
45
  (SDE.config.table_prefix.to_s + name.gsub(/^#{SDE::PREFIXES.join('|')}/, '')).pluralize.underscore
40
46
  end
@@ -3,6 +3,7 @@ module EveApp
3
3
  module Downloader
4
4
  def download
5
5
  within SDE.config.tmp_path do
6
+ execute :rm, '-f', 'postgres-latest*'
6
7
  execute :wget, '-q', download_uri + '{,.md5}'
7
8
  verify!
8
9
  execute :bunzip2, SDE.config.archive
@@ -10,9 +11,9 @@ module EveApp
10
11
  end
11
12
 
12
13
  def restore
13
- table_list.each do |table_name,normalized_name|
14
+ table_list.each do |table_name,info|
14
15
  sql %Q(DROP TABLE IF EXISTS "#{table_name}")
15
- sql %Q(DROP TABLE IF EXISTS "#{normalized_name}")
16
+ sql %Q(DROP TABLE IF EXISTS "#{info[:name]}")
16
17
  end
17
18
 
18
19
  options = ['-x -O']
@@ -2,18 +2,26 @@ module EveApp
2
2
  module SDE
3
3
  module Normalizer
4
4
  def normalize
5
- table_names
5
+ normalize_table_names
6
+ primary_keys
6
7
  column_names
7
8
  missing_relations
8
9
  indexes
9
10
  end
10
11
 
11
- def table_names
12
- table_list.each do |table_name, normalized_name|
12
+ def normalize_table_names
13
+ table_names.each do |table_name, normalized_name|
13
14
  sql %Q(ALTER TABLE IF EXISTS "#{table_name}" RENAME TO "#{normalized_name}")
14
15
  end
15
16
  end
16
17
 
18
+ def primary_keys
19
+ tables = table_list.select { |_, info| info[:add_primary] }
20
+ tables.values.each do |info|
21
+ sql %Q(ALTER TABLE #{info[:name]} ADD id SERIAL PRIMARY KEY)
22
+ end
23
+ end
24
+
17
25
  def column_names
18
26
  columns.each do |row|
19
27
  resource_name = row[:table_name].singularize.gsub('eve_', '')
@@ -21,7 +29,9 @@ module EveApp
21
29
  if row[:target_column_name].starts_with?(resource_name)
22
30
  row[:target_column_name] = row[:target_column_name].gsub("#{resource_name}_", "")
23
31
  end
24
-
32
+ if row[:target_column_name] == 'id' && table_info(row[:table_name]).add_primary
33
+ next
34
+ end
25
35
  if row[:column_name] != row[:target_column_name]
26
36
  sql %Q(ALTER TABLE "#{row[:table_name]}" RENAME COLUMN "#{row[:column_name]}" TO "#{row[:target_column_name]}")
27
37
  end
@@ -35,49 +45,40 @@ module EveApp
35
45
  end
36
46
  if row[:column_name] == 'id'
37
47
  sql %Q(ALTER TABLE #{row[:table_name]} DROP CONSTRAINT IF EXISTS #{row[:table_name]}_pkey)
38
-
39
- if complex_id_index?(row[:table_name])
40
- sql %Q(ALTER TABLE #{row[:table_name]} ADD PRIMARY KEY (id, type_id))
41
- else
42
- sql %Q(ALTER TABLE #{row[:table_name]} ADD PRIMARY KEY (id))
43
- end
48
+ sql %Q(ALTER TABLE #{row[:table_name]} ADD PRIMARY KEY (id))
44
49
  end
45
50
  end
46
51
  end
47
52
 
48
53
  def missing_relations
49
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD IF NOT EXISTS category_id integer)
50
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD IF NOT EXISTS category_name character varying)
51
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD IF NOT EXISTS group_name character varying)
52
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD IF NOT EXISTS market_group_name character varying)
53
- sql %Q(ALTER TABLE #{table_list['invMarketGroups']} ADD root_group_id INTEGER DEFAULT NULL)
54
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD market_group_root_id integer)
55
- sql %Q(ALTER TABLE #{table_list['invTypes']} ADD blueprint_type_id integer)
56
- sql %Q(UPDATE #{table_list['invTypes']} SET group_name = (SELECT name FROM #{table_list['invGroups']} WHERE id = #{table_list['invTypes']}.group_id))
57
- sql %Q(UPDATE #{table_list['invTypes']} SET category_id = (SELECT category_id FROM #{table_list['invGroups']} WHERE id = #{table_list['invTypes']}.group_id))
58
- sql %Q(UPDATE #{table_list['invTypes']} SET category_name = (SELECT name FROM #{table_list['invCategories']} WHERE id = #{table_list['invTypes']}.category_id))
59
- sql %Q(UPDATE #{table_list['invTypes']} SET market_group_name = (SELECT name FROM #{table_list['invMarketGroups']} WHERE id = #{table_list['invTypes']}.market_group_id))
60
- sql %Q(UPDATE #{table_list['invTypes']} SET blueprint_type_id = (SELECT type_id FROM #{table_list['industryActivityProducts']} WHERE activity_id = 1 AND product_type_id = #{table_list['invTypes']}.id LIMIT 1))
54
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD IF NOT EXISTS category_id integer)
55
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD IF NOT EXISTS category_name character varying)
56
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD IF NOT EXISTS group_name character varying)
57
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD IF NOT EXISTS market_group_name character varying)
58
+ sql %Q(ALTER TABLE #{table_names['invMarketGroups']} ADD root_group_id INTEGER DEFAULT NULL)
59
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD market_group_root_id integer)
60
+ sql %Q(ALTER TABLE #{table_names['invTypes']} ADD blueprint_type_id integer)
61
+ sql %Q(UPDATE #{table_names['invTypes']} SET group_name = (SELECT name FROM #{table_names['invGroups']} WHERE id = #{table_names['invTypes']}.group_id))
62
+ sql %Q(UPDATE #{table_names['invTypes']} SET category_id = (SELECT category_id FROM #{table_names['invGroups']} WHERE id = #{table_names['invTypes']}.group_id))
63
+ sql %Q(UPDATE #{table_names['invTypes']} SET category_name = (SELECT name FROM #{table_names['invCategories']} WHERE id = #{table_names['invTypes']}.category_id))
64
+ sql %Q(UPDATE #{table_names['invTypes']} SET market_group_name = (SELECT name FROM #{table_names['invMarketGroups']} WHERE id = #{table_names['invTypes']}.market_group_id))
65
+ sql %Q(UPDATE #{table_names['invTypes']} SET blueprint_type_id = (SELECT type_id FROM #{table_names['industryActivityProducts']} WHERE activity_id = 1 AND product_type_id = #{table_names['invTypes']}.id LIMIT 1))
61
66
 
62
67
  sql %Q(
63
68
  WITH RECURSIVE mg_roots(id, root_id) AS (
64
- SELECT mg.id, mg.id AS root_id FROM #{table_list['invMarketGroups']} AS mg WHERE mg.parent_group_id IS NULL
69
+ SELECT mg.id, mg.id AS root_id FROM #{table_names['invMarketGroups']} AS mg WHERE mg.parent_group_id IS NULL
65
70
  UNION ALL
66
- SELECT c.id, p.root_id FROM mg_roots AS p, #{table_list['invMarketGroups']} AS c WHERE c.parent_group_id = p.id
71
+ SELECT c.id, p.root_id FROM mg_roots AS p, #{table_names['invMarketGroups']} AS c WHERE c.parent_group_id = p.id
67
72
  )
68
- UPDATE #{table_list['invMarketGroups']} SET root_group_id = mg_roots.root_id FROM (
73
+ UPDATE #{table_names['invMarketGroups']} SET root_group_id = mg_roots.root_id FROM (
69
74
  SELECT id, root_id FROM mg_roots WHERE root_id != id
70
- ) AS mg_roots WHERE #{table_list['invMarketGroups']}.id = mg_roots.id;
75
+ ) AS mg_roots WHERE #{table_names['invMarketGroups']}.id = mg_roots.id;
71
76
  )
72
- sql %Q(UPDATE #{table_list['invTypes']} SET market_group_root_id = (SELECT root_group_id FROM #{table_list['invMarketGroups']} WHERE id = #{table_list['invTypes']}.market_group_id))
77
+ sql %Q(UPDATE #{table_names['invTypes']} SET market_group_root_id = (SELECT root_group_id FROM #{table_names['invMarketGroups']} WHERE id = #{table_names['invTypes']}.market_group_id))
73
78
  end
74
79
 
75
80
  private
76
81
 
77
- def complex_id_index?(table_name)
78
- SDE::ID_TYPE_INDEX.include?(table_name.gsub("#{SDE.config.table_prefix.to_s}_", ''))
79
- end
80
-
81
82
  def columns
82
83
  query = %Q(
83
84
  SELECT table_name, column_name, ordinal_position
@@ -85,7 +86,7 @@ module EveApp
85
86
  WHERE
86
87
  table_catalog = '#{db_config[:database]}' AND
87
88
  table_schema = 'public' AND
88
- table_name IN(#{table_list.values.map { |n| "'#{n}'" }.join(', ')})
89
+ table_name IN(#{table_names.values.map { |n| "'#{n}'" }.join(', ')})
89
90
  )
90
91
  db.select_all(query).map(&:symbolize_keys)
91
92
  end
@@ -110,6 +111,10 @@ module EveApp
110
111
  )
111
112
  count.to_i > 0
112
113
  end
114
+
115
+ def table_info(table_name)
116
+ OpenStruct.new(table_list.detect { |(name,info)| [name, info[:name]].include?(table_name) }[1])
117
+ end
113
118
  end
114
119
  end
115
120
  end
data/lib/eve_app/sde.rb CHANGED
@@ -12,15 +12,18 @@ module EveApp
12
12
  table_list_file: EveApp.root.join('lib', 'table-list.yml')
13
13
  }
14
14
  PREFIXES = %w(agt dgm map trn inv sta industry ram)
15
- ID_TYPE_INDEX = %w(activities)
16
15
 
17
16
  class << self
18
17
  def config
19
18
  @_config ||= OpenStruct.new(DEFAULT_CONFIG)
20
19
  end
21
20
 
21
+ def table_info
22
+ @_table_info ||= YAML::load_file(config.table_list_file)
23
+ end
24
+
22
25
  def table_list
23
- @_table_list ||= YAML::load_file(config.table_list_file)
26
+ @_table_list ||= table_info.keys
24
27
  end
25
28
  end
26
29
  end
@@ -1,3 +1,3 @@
1
1
  module EveApp
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
data/lib/eve_app.rb CHANGED
@@ -21,15 +21,3 @@ module EveApp
21
21
  end
22
22
  end
23
23
  end
24
-
25
- if defined?(::Rails)
26
- module ::Rails
27
- class Application
28
- rake_tasks do
29
- Dir[File.join(EveApp.root, "/lib/tasks/", "**/*.rake")].each do |file|
30
- load file
31
- end
32
- end
33
- end
34
- end
35
- end
data/lib/table-list.yml CHANGED
@@ -1,88 +1,177 @@
1
- - agtAgentTypes
2
- - agtAgents
3
- - agtResearchAgents
4
- - certCerts
5
- - certMasteries
6
- - certSkills
7
- - chrAncestries
8
- - chrAttributes
9
- - chrBloodlines
10
- - chrFactions
11
- - chrRaces
12
- - crpActivities
13
- - crpNPCCorporationDivisions
14
- - crpNPCCorporationResearchFields
15
- - crpNPCCorporationTrades
16
- - crpNPCCorporations
17
- - crpNPCDivisions
18
- - dgmAttributeCategories
19
- - dgmAttributeTypes
20
- - dgmEffects
21
- - dgmExpressions
22
- - dgmTypeAttributes
23
- - dgmTypeEffects
24
- - eveGraphics
25
- - eveIcons
26
- - eveUnits
27
- - industryActivity
28
- - industryActivityMaterials
29
- - industryActivityProbabilities
30
- - industryActivityProducts
31
- - industryActivityRaces
32
- - industryActivitySkills
33
- - industryBlueprints
34
- - invCategories
35
- - invContrabandTypes
36
- - invControlTowerResourcePurposes
37
- - invControlTowerResources
38
- - invFlags
39
- - invGroups
40
- - invItems
41
- - invMarketGroups
42
- - invMetaGroups
43
- - invMetaTypes
44
- - invNames
45
- - invPositions
46
- - invTraits
47
- - invTypeMaterials
48
- - invTypeReactions
49
- - invTypes
50
- - invUniqueNames
51
- - invVolumes
52
- - mapCelestialStatistics
53
- - mapConstellationJumps
54
- - mapConstellations
55
- - mapDenormalize
56
- - mapJumps
57
- - mapLandmarks
58
- - mapLocationScenes
59
- - mapLocationWormholeClasses
60
- - mapRegionJumps
61
- - mapRegions
62
- - mapSolarSystemJumps
63
- - mapSolarSystems
64
- - mapUniverse
65
- - planetSchematics
66
- - planetSchematicsPinMap
67
- - planetSchematicsTypeMap
68
- - ramActivities
69
- - ramAssemblyLineStations
70
- - ramAssemblyLineTypeDetailPerCategory
71
- - ramAssemblyLineTypeDetailPerGroup
72
- - ramAssemblyLineTypes
73
- - ramInstallationTypeContents
74
- - skinLicense
75
- - skinMaterials
76
- - skinShip
77
- - skins
78
- - staOperationServices
79
- - staOperations
80
- - staServices
81
- - staStationTypes
82
- - staStations
83
- - translationTables
84
- - trnTranslationColumns
85
- - trnTranslationLanguages
86
- - trnTranslations
87
- - warCombatZoneSystems
88
- - warCombatZones
1
+ ---
2
+ agtAgentTypes:
3
+ add_primary: false
4
+ agtAgents:
5
+ add_primary: false
6
+ agtResearchAgents:
7
+ add_primary: false
8
+ certCerts:
9
+ add_primary: false
10
+ certMasteries:
11
+ add_primary: false
12
+ certSkills:
13
+ add_primary: false
14
+ chrAncestries:
15
+ add_primary: false
16
+ chrAttributes:
17
+ add_primary: false
18
+ chrBloodlines:
19
+ add_primary: false
20
+ chrFactions:
21
+ add_primary: false
22
+ chrRaces:
23
+ add_primary: false
24
+ crpActivities:
25
+ add_primary: false
26
+ crpNPCCorporationDivisions:
27
+ add_primary: false
28
+ crpNPCCorporationResearchFields:
29
+ add_primary: false
30
+ crpNPCCorporationTrades:
31
+ add_primary: false
32
+ crpNPCCorporations:
33
+ add_primary: false
34
+ crpNPCDivisions:
35
+ add_primary: false
36
+ dgmAttributeCategories:
37
+ add_primary: false
38
+ dgmAttributeTypes:
39
+ add_primary: false
40
+ dgmEffects:
41
+ add_primary: false
42
+ dgmExpressions:
43
+ add_primary: false
44
+ dgmTypeAttributes:
45
+ add_primary: false
46
+ dgmTypeEffects:
47
+ add_primary: false
48
+ eveGraphics:
49
+ add_primary: false
50
+ eveIcons:
51
+ add_primary: false
52
+ eveUnits:
53
+ add_primary: false
54
+ industryActivity:
55
+ add_primary: true
56
+ industryActivityMaterials:
57
+ add_primary: true
58
+ industryActivityProbabilities:
59
+ add_primary: false
60
+ industryActivityProducts:
61
+ add_primary: false
62
+ industryActivityRaces:
63
+ add_primary: false
64
+ industryActivitySkills:
65
+ add_primary: false
66
+ industryBlueprints:
67
+ add_primary: false
68
+ invCategories:
69
+ add_primary: false
70
+ invContrabandTypes:
71
+ add_primary: false
72
+ invControlTowerResourcePurposes:
73
+ add_primary: false
74
+ invControlTowerResources:
75
+ add_primary: false
76
+ invFlags:
77
+ add_primary: false
78
+ invGroups:
79
+ add_primary: false
80
+ invItems:
81
+ add_primary: false
82
+ invMarketGroups:
83
+ add_primary: false
84
+ invMetaGroups:
85
+ add_primary: false
86
+ invMetaTypes:
87
+ add_primary: false
88
+ invNames:
89
+ add_primary: false
90
+ invPositions:
91
+ add_primary: false
92
+ invTraits:
93
+ add_primary: false
94
+ invTypeMaterials:
95
+ add_primary: false
96
+ invTypeReactions:
97
+ add_primary: false
98
+ invTypes:
99
+ add_primary: false
100
+ invUniqueNames:
101
+ add_primary: false
102
+ invVolumes:
103
+ add_primary: false
104
+ mapCelestialStatistics:
105
+ add_primary: false
106
+ mapConstellationJumps:
107
+ add_primary: false
108
+ mapConstellations:
109
+ add_primary: false
110
+ mapDenormalize:
111
+ add_primary: false
112
+ mapJumps:
113
+ add_primary: false
114
+ mapLandmarks:
115
+ add_primary: false
116
+ mapLocationScenes:
117
+ add_primary: false
118
+ mapLocationWormholeClasses:
119
+ add_primary: false
120
+ mapRegionJumps:
121
+ add_primary: false
122
+ mapRegions:
123
+ add_primary: false
124
+ mapSolarSystemJumps:
125
+ add_primary: false
126
+ mapSolarSystems:
127
+ add_primary: false
128
+ mapUniverse:
129
+ add_primary: false
130
+ planetSchematics:
131
+ add_primary: false
132
+ planetSchematicsPinMap:
133
+ add_primary: false
134
+ planetSchematicsTypeMap:
135
+ add_primary: false
136
+ ramActivities:
137
+ add_primary: false
138
+ ramAssemblyLineStations:
139
+ add_primary: false
140
+ ramAssemblyLineTypeDetailPerCategory:
141
+ add_primary: false
142
+ ramAssemblyLineTypeDetailPerGroup:
143
+ add_primary: false
144
+ ramAssemblyLineTypes:
145
+ add_primary: false
146
+ ramInstallationTypeContents:
147
+ add_primary: false
148
+ skinLicense:
149
+ add_primary: false
150
+ skinMaterials:
151
+ add_primary: false
152
+ skinShip:
153
+ add_primary: false
154
+ skins:
155
+ add_primary: false
156
+ staOperationServices:
157
+ add_primary: false
158
+ staOperations:
159
+ add_primary: false
160
+ staServices:
161
+ add_primary: false
162
+ staStationTypes:
163
+ add_primary: false
164
+ staStations:
165
+ add_primary: false
166
+ translationTables:
167
+ add_primary: false
168
+ trnTranslationColumns:
169
+ add_primary: false
170
+ trnTranslationLanguages:
171
+ add_primary: false
172
+ trnTranslations:
173
+ add_primary: false
174
+ warCombatZoneSystems:
175
+ add_primary: false
176
+ warCombatZones:
177
+ add_primary: false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eve_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Hiemstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-28 00:00:00.000000000 Z
11
+ date: 2017-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails