eitje_s3 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 780e597f34264cf258ebe42c734869d0e5c7603184dd12cd6279eea60c9cb9a5
4
- data.tar.gz: 35d61bacafe58fb85b3e0af7c24828d11c999fc46550c43f78a2d1700b7438b2
3
+ metadata.gz: 6849a57128be891415bc470d167489cd60be8d1e39f5aeb439b82afcfc0f83c3
4
+ data.tar.gz: 569b8280b4c64fe6e18510d20bb44952074e735fff4f0e06ef0ebebc446e6eaf
5
5
  SHA512:
6
- metadata.gz: 725400574bf70d36594ce8b5f86f62dbaced343f0d2da6a0a74ca124e9be3a785c997b9e2f2ed53084203088d0131ca12ce06c05116b9c07bbc2faa32a5eb511
7
- data.tar.gz: 2fffbdb653da51accf6c157cc71ecbf246209f78e292d0caad78689b3cab7e081b9dd9d5eb1f0cef85ba84a25780f482e96bdddab79c0a161cb2339a971aebef
6
+ metadata.gz: bd9864943eb8553e0b67a93a0ede6d477de9de5711a9292ac61c9b6af2c2bec4d439a7f8e0c55876cdeb0b498e8de0bdc7cb6ccbac334775a0ac6454160cda97
7
+ data.tar.gz: 641af7b9cd04053158bcaacd4b36bd595fe85ff7a60730e2eb602979a37d0492db25dd2b293af79b099ef8944aa755a88b905643f2c563b85e3321354ecf2060
@@ -1,13 +1,7 @@
1
1
  module S3::NewDeletedRecordsService
2
2
  class << self
3
3
 
4
- DB_TABLES = %w$ shifts teams users contracts infos posts $
5
-
6
- def test(table)
7
- S3::NewDeletedRecordsService.get_records(
8
- db_table: table, start_date: '2021-03-28', end_date: '2021-04-3', env_id: 513
9
- )
10
- end
4
+ DB_TABLES = %w$ shifts teams users contracts infos posts topics $
11
5
 
12
6
  def get_records(db_table:, start_date:, end_date:, env_id:)
13
7
  @date_range = Date.parse(start_date)..Date.parse(end_date)
@@ -32,7 +26,13 @@ module S3::NewDeletedRecordsService
32
26
  end
33
27
 
34
28
  def query_records
35
- file = @s3.get_object(bucket: 'eitje-deleted-jurr', key: @file_name)
29
+
30
+ # Previously (before adding 'topics') the request bucket was 'eitje-deleted-jurr'
31
+ # but somehow topics break if we dont request the bucket '-2'. Now for other tables
32
+ # the original returns waaaaay many records, so probably does not filter by date or
33
+ # something. Change for now and investigate if shit goes BG.
34
+
35
+ file = @s3.get_object(bucket: 'eitje-deleted-jurr-2', key: @file_name)
36
36
  @records = JSON.parse(file.body.read.as_json).map(&:symbolize_keys)
37
37
  end
38
38
 
@@ -1,9 +1,7 @@
1
1
  module S3::OldDeletedRecordsService
2
2
  class << self
3
3
 
4
- DB_TABLES = %w$ shifts teams users contracts infos posts $
5
-
6
- # S3::OldDeletedRecordsService.get_records(env_id: 307, env_name: 'Kua - Den Haag', db_table: 'verlofverzoeks', start_date: '2021-02-01', end_date: '2021-04-01')
4
+ DB_TABLES = %w$ shifts teams users contracts infos posts topics $
7
5
 
8
6
  def get_records(db_table:, start_date:, end_date:, env_id:, env_name:)
9
7
 
@@ -20,7 +18,6 @@ module S3::OldDeletedRecordsService
20
18
  @file_names_filtered_by_date = filter_by_date
21
19
 
22
20
  read_all_files
23
-
24
21
  end
25
22
 
26
23
  # validations
@@ -36,7 +33,15 @@ module S3::OldDeletedRecordsService
36
33
 
37
34
  @file_name = file_name
38
35
  @file = request_object
39
- @db_table == 'users' ? filter_users_table_by_env : filter_file_by_env
36
+
37
+ case @db_table
38
+ when 'users'
39
+ filter_users_table_by_env
40
+ when 'topics'
41
+ filter_topics_table_by_env
42
+ else
43
+ filter_file_by_env
44
+ end
40
45
 
41
46
  end.flatten
42
47
  end
@@ -59,6 +64,10 @@ module S3::OldDeletedRecordsService
59
64
  @file.select { |row| row[:envs].include? @env_name }
60
65
  end
61
66
 
67
+ def filter_topics_table_by_env
68
+ @file.select { |row| row[:environment_ids]&.include?(@env_id) }
69
+ end
70
+
62
71
  def filter_by_date
63
72
  @file_names_filtered_by_table.select { |file_name| @date_range.include?(get_date(file_name)) }
64
73
  end
@@ -22,15 +22,23 @@ module S3::TransformDeletedFilesService
22
22
  set_tables.each do |table|
23
23
  object = s3.get_object(bucket: 'eitje-backups', key: "#{table}/#{start_date.strftime("%Y-%m-%d")}.json")
24
24
  json = JSON.parse(object.body.read.as_json).map(&:symbolize_keys)
25
- env_ids = json.map {|row| row[:env]}.uniq.map { |name| Environment.find_by(naam: name)&.id }
25
+
26
+ if table == 'topics'
27
+ env_ids = json.map {|row| row[:environment_ids]}.flatten.compact.uniq
28
+ else
29
+ env_ids = json.map {|row| row[:env]}.uniq.map { |name| Environment.find_by(naam: name)&.id }
30
+ end
31
+
26
32
  envs_to_migrate << env_ids
27
- rescue
33
+ rescue => e
28
34
  # in case the file does not exist on S3, cause there are no deleted
29
35
  # records, skip to next table
30
36
  next
31
37
  end
38
+
39
+ envs_to_migrate = envs_to_migrate.flatten.uniq.compact
32
40
 
33
- envs_to_migrate.flatten.uniq.each { |env_id| migrate_files_single_env(env_id, start_date: start_date, skip_setters: true) }
41
+ envs_to_migrate.each { |env_id| migrate_files_single_env(env_id, start_date: start_date, skip_setters: true) }
34
42
  end
35
43
 
36
44
  def migrate_files_single_env(environment_id, start_date: Date.yesterday, skip_setters: false)
@@ -100,7 +108,8 @@ module S3::TransformDeletedFilesService
100
108
 
101
109
  (@records += @existing_records) if @existing_records
102
110
  set_json
103
- upload_file
111
+ upload_file
112
+
104
113
  rescue => e
105
114
  @logger.error "Error for env #{@env.naam} (##{@env.id}) with table '#{@table}' => #{e.class}: #{e.message}.\n\nBacktrace:#{e.backtrace}\n"
106
115
  end
data/lib/s3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitje_s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2021-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.3
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.3
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk-s3
29
29
  requirement: !ruby/object:Gem::Requirement