eitje_s3 1.0.2 → 1.1.1

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: d33b9a4100b9da596c8144c2a7a568f0afdb93157c5ab16e734fbdd3bd1d0648
4
- data.tar.gz: 83e8c75c8cb6f91b4277b2bd23dcaf9186c771f342c60d95d9c31960a6d14f2e
3
+ metadata.gz: 71fa767da62f09f63fe6a2d3da4d3b05d88002dffb1c1163af0e4b6be9fabb82
4
+ data.tar.gz: 5e14301d327038d95a7439c53eb2e3d1393a9ff7d59f75dfaa87ac66895a0ddb
5
5
  SHA512:
6
- metadata.gz: 3b8abb2833763749a92555cd4453bb732f11df97f13a466310bb3f0fced1ca4f7c930062f354b6e234fea9161ecf9ad2f770d14136093ebec3093bd0732b0eab
7
- data.tar.gz: 7ef3fe024ca91e1a8ceef0e62d21d6066baed5fe52717a75eabcaec9562681bfd4520ab372ab2308e96b29048e152f2d52c9f3455b974cc1890b082eecfd7432
6
+ metadata.gz: fe8c94a7707711d185dfa43b1dc63647ec67f1573faea4739c86cb0cb3eaba6bed226f7c6ff4f661b1406e74ea4d192928eabb5c78fb803966355478d9995257
7
+ data.tar.gz: 0f7afb80b297bf439d0487e2847ac405fd711f0da7eb16db3de1ed85086986bf33305f1abd93f57c76cbe7ae220bc8fee5470e3c1bc213433d728181b06bedf1
@@ -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
 
@@ -3,8 +3,6 @@ module S3::OldDeletedRecordsService
3
3
 
4
4
  DB_TABLES = %w$ shifts teams users contracts infos posts topics $
5
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')
7
-
8
6
  def get_records(db_table:, start_date:, end_date:, env_id:, env_name:)
9
7
 
10
8
  # validate_args(db_table)
@@ -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.2'
2
+ VERSION = '1.1.1'
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.2
4
+ version: 1.1.1
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-07-20 00:00:00.000000000 Z
11
+ date: 2021-11-12 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
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.1.2
96
+ rubygems_version: 3.0.9
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: S3