eitje_s3 1.0.0 → 1.0.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: b3fab11f169aa044513495cd47f13853ec305a31fe72e5075b681f042d9712c8
4
- data.tar.gz: 464f079e85d4e7df5373d70732ba93852ff9489b3d543404eee769d6d5e86dec
3
+ metadata.gz: 780e597f34264cf258ebe42c734869d0e5c7603184dd12cd6279eea60c9cb9a5
4
+ data.tar.gz: 35d61bacafe58fb85b3e0af7c24828d11c999fc46550c43f78a2d1700b7438b2
5
5
  SHA512:
6
- metadata.gz: a8c6436222d6708cbe69ae3d4d38e97c6a015db22e870639520ea05ee36ad721fadb7cae6eac3daeb53a5649035ead3562d654865f785c2f2e8e77468b2647cf
7
- data.tar.gz: 47f1b3af7e66c4740d8a4fcba65d824096e4287a0b22d122d2e132fbc37b660e573ac18ff3c38b72e1a0539dbf8540c792fcab032f9e1ebe77efc0ad0c399319
6
+ metadata.gz: 725400574bf70d36594ce8b5f86f62dbaced343f0d2da6a0a74ca124e9be3a785c997b9e2f2ed53084203088d0131ca12ce06c05116b9c07bbc2faa32a5eb511
7
+ data.tar.gz: 2fffbdb653da51accf6c157cc71ecbf246209f78e292d0caad78689b3cab7e081b9dd9d5eb1f0cef85ba84a25780f482e96bdddab79c0a161cb2339a971aebef
@@ -5,24 +5,53 @@ module S3::TransformDeletedFilesService
5
5
 
6
6
  BUCKET = 'eitje-deleted-jurr-2'
7
7
 
8
- def migrate_files(start_date: '2019-07-18')
8
+ def set_setters(start_date = Date.yesterday)
9
9
  @start_date = start_date
10
-
11
10
  set_logger
12
11
  set_bucket
13
12
  set_tables
14
13
  set_dates(start_date)
14
+ end
15
+
16
+ def migrate_files(start_date: Date.today)
17
+ set_setters(start_date)
18
+
19
+ s3 = Aws::S3::Client.new
20
+ envs_to_migrate = []
21
+
22
+ set_tables.each do |table|
23
+ object = s3.get_object(bucket: 'eitje-backups', key: "#{table}/#{start_date.strftime("%Y-%m-%d")}.json")
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 }
26
+ envs_to_migrate << env_ids
27
+ rescue
28
+ # in case the file does not exist on S3, cause there are no deleted
29
+ # records, skip to next table
30
+ next
31
+ end
32
+
33
+ envs_to_migrate.flatten.uniq.each { |env_id| migrate_files_single_env(env_id, start_date: start_date, skip_setters: true) }
34
+ end
15
35
 
16
- Environment.find_each do |env|
17
- @env = env
18
-
19
- @tables.each do |table|
20
- @table = table
21
- compose_file
22
- end
36
+ def migrate_files_single_env(environment_id, start_date: Date.yesterday, skip_setters: false)
37
+ set_setters(start_date) unless skip_setters
38
+ @env = Environment.find(environment_id)
39
+ @tables.each do |table|
40
+ @table = table
41
+ compose_file
23
42
  end
24
43
  end
25
44
 
45
+ def migrate_files_multi_env(environment_ids, start_date: Date.yesterday)
46
+ set_setters(start_date)
47
+ environment_ids.each { |id| migrate_files_single_env(id, start_date: start_date, skip_setters: true) }
48
+ end
49
+
50
+ def migrate_files_single_org(organisation_id, start_date: Date.yesterday)
51
+ env_ids = Organisation.find(organisation_id).environment_ids
52
+ migrate_files_multi_env(env_ids, start_date: start_date)
53
+ end
54
+
26
55
  def set_logger
27
56
  @logger = Logger.new "log/migrate_deleted_records_#{DateTime.now.strftime('%Y_%m_%d_%H:%M:%S')}.log"
28
57
  end
@@ -32,8 +61,7 @@ module S3::TransformDeletedFilesService
32
61
  end
33
62
 
34
63
  def set_tables
35
- # @tables = S3::OldDeletedRecordsService::singleton_class::DB_TABLES
36
- @tables = ['verlof_verzoeken']
64
+ @tables = S3::OldDeletedRecordsService::singleton_class::DB_TABLES
37
65
  end
38
66
 
39
67
  def set_dates(start_date)
@@ -46,7 +74,7 @@ module S3::TransformDeletedFilesService
46
74
  end
47
75
 
48
76
  def set_records
49
- @records = S3::OldDeletedRecordsService.get_records(env_id: @env.id, env_name: @env.naam, db_table: 'verlofverzoeks', **@dates)
77
+ @records = S3::OldDeletedRecordsService.get_records(env_id: @env.id, env_name: @env.naam, db_table: @table, **@dates)
50
78
  end
51
79
 
52
80
  def set_json
data/lib/s3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitje_s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer