maisaedu-poormans-dms 1.1.73__tar.gz → 1.1.75__tar.gz

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.
Files changed (44) hide show
  1. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/PKG-INFO +1 -1
  2. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/MigratorRedshift.py +15 -3
  3. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Writer/GenericWriter.py +36 -2
  4. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms.egg-info/PKG-INFO +1 -1
  5. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/setup.py +1 -1
  6. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/LICENSE +0 -0
  7. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/__init__.py +0 -0
  8. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/MigratorInterface.py +0 -0
  9. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/MigratorRowInterface.py +0 -0
  10. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/MigratorRowReaderInterface.py +0 -0
  11. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/MigratorRowWriterInterface.py +0 -0
  12. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/MigratorTableInterface.py +0 -0
  13. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Contracts/__init__.py +0 -0
  14. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/Migrator.py +0 -0
  15. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/MigratorRow/MigratorRow.py +0 -0
  16. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/MigratorRow/Reader.py +0 -0
  17. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/MigratorRow/Writer.py +0 -0
  18. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/MigratorRow/__init__.py +0 -0
  19. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/MigratorTable.py +0 -0
  20. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/postgres_migration/__init__.py +0 -0
  21. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Connector.py +0 -0
  22. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Contracts/WriterInterface.py +0 -0
  23. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Contracts/__init__.py +0 -0
  24. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Logger.py +0 -0
  25. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Models/ExtractionOperation.py +0 -0
  26. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Models/Struct.py +0 -0
  27. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Models/__init__.py +0 -0
  28. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Reader.py +0 -0
  29. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Services/AdapterSourceTarget.py +0 -0
  30. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Services/ExtractionOperation.py +0 -0
  31. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Services/RelationExtraction.py +0 -0
  32. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Services/Struct.py +0 -0
  33. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Services/__init__.py +0 -0
  34. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Types.py +0 -0
  35. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Writer/WriterCDC.py +0 -0
  36. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Writer/WriterNonCDC.py +0 -0
  37. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/Writer/__init__.py +0 -0
  38. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/redshift_migration/__init__.py +0 -0
  39. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms/sql_server_migration.py +0 -0
  40. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms.egg-info/SOURCES.txt +0 -0
  41. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms.egg-info/dependency_links.txt +0 -0
  42. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms.egg-info/requires.txt +0 -0
  43. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/maisaedu_poormans_dms.egg-info/top_level.txt +0 -0
  44. {maisaedu-poormans-dms-1.1.73 → maisaedu-poormans-dms-1.1.75}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maisaedu-poormans-dms
3
- Version: 1.1.73
3
+ Version: 1.1.75
4
4
  Summary: A library for making database migration tasks, for +A Education
5
5
  Home-page: UNKNOWN
6
6
  Author: A+ Educação
@@ -81,6 +81,7 @@ class MigratorRedshift:
81
81
  return True
82
82
 
83
83
  def __run_incremental_cdc_flow(self):
84
+ perfomed_operations = False
84
85
  has_more = True
85
86
  extraction_operation_service = ExtractionOperation(
86
87
  conn=self.migrator_redshift_connector.target_conn
@@ -100,7 +101,12 @@ class MigratorRedshift:
100
101
  status=SAVED_REDSHIFT,
101
102
  )
102
103
 
104
+ perfomed_operations = True
105
+
106
+ return perfomed_operations
107
+
103
108
  def __run_non_cdc_flow(self, load_option):
109
+ perfomed_operations = False
104
110
  if load_option == FULL or self.target_table_has_data is False:
105
111
  RelationExtraction(
106
112
  conn=self.migrator_redshift_connector.target_conn
@@ -112,6 +118,8 @@ class MigratorRedshift:
112
118
  operation = self.migrator_redshift_reader.save_data_to_s3(load_option)
113
119
  if operation is not None:
114
120
  self.migrator_redshift_writer.save_to_redshift([operation])
121
+ perfomed_operations = True
122
+
115
123
  ExtractionOperation(
116
124
  conn=self.migrator_redshift_connector.target_conn
117
125
  ).update(
@@ -134,7 +142,8 @@ class MigratorRedshift:
134
142
  struct=self.struct,
135
143
  is_active=True,
136
144
  )
137
-
145
+
146
+ return perfomed_operations
138
147
 
139
148
  def extract_to_redshift(self, load_option=None):
140
149
  check_if_option_is_valid(load_option)
@@ -150,9 +159,12 @@ class MigratorRedshift:
150
159
  )
151
160
 
152
161
  if update_by_cdc is True:
153
- self.__run_incremental_cdc_flow()
162
+ perfomed_operations = self.__run_incremental_cdc_flow()
154
163
  else:
155
- self.__run_non_cdc_flow(load_option)
164
+ perfomed_operations = self.__run_non_cdc_flow(load_option)
165
+
166
+ if perfomed_operations is True:
167
+ self.migrator_redshift_writer.clean_duplicate_inconsistencies()
156
168
 
157
169
  self.migrator_redshift_connector.close_target()
158
170
 
@@ -25,6 +25,23 @@ class GenericWriter:
25
25
  """
26
26
  )
27
27
 
28
+ def create_table_temp_target_relation_to_remove_dups(self):
29
+ pk_columns = ", ".join(self.struct.columns_upsert)
30
+
31
+ self.target_cursor.execute(
32
+ f"""
33
+ create temp table {self.temp_target_relation} as (
34
+ SELECT distinct a.* FROM {self.target_relation} as a
35
+ join (
36
+ SELECT {pk_columns}, count(*) FROM {self.target_relation}
37
+ group by {pk_columns} having count(*) > 1
38
+ ) as subselect
39
+ on 1=1
40
+ {self.create_statement_comparison_pk_columns('subselect', 'a')}
41
+ );
42
+ """
43
+ )
44
+
28
45
  def copy_data_to_target(self, url, target):
29
46
  self.target_cursor.execute(
30
47
  f"""
@@ -53,7 +70,7 @@ class GenericWriter:
53
70
  DELETE FROM {self.target_relation}
54
71
  USING {self.temp_target_relation}
55
72
  WHERE 1=1
56
- {self.create_statement_delete(self.target_relation, self.temp_target_relation)}
73
+ {self.create_statement_comparison_pk_columns(self.target_relation, self.temp_target_relation)}
57
74
  ;
58
75
  """
59
76
  )
@@ -78,7 +95,7 @@ class GenericWriter:
78
95
  return "SERIALIZETOJSON"
79
96
  return ""
80
97
 
81
- def create_statement_delete(self, target_relation, temp_target_relation):
98
+ def create_statement_comparison_pk_columns(self, target_relation, temp_target_relation):
82
99
  statement_upsert = ""
83
100
  for c in self.struct.columns_upsert:
84
101
  statement_upsert = (
@@ -89,6 +106,23 @@ class GenericWriter:
89
106
  )
90
107
 
91
108
  return statement_upsert
109
+
110
+ def clean_duplicate_inconsistencies(self):
111
+ cursor = self.migrator_redshift_connector.target_conn.cursor()
112
+
113
+ self.target_cursor = cursor
114
+
115
+ self.migrator_redshift_connector.target_conn.autocommit = False
116
+
117
+ self.set_temp_target_relation()
118
+ self.set_target_relation()
119
+ self.create_table_temp_target_relation_to_remove_dups()
120
+ self.delete_using_temp_target_from_target()
121
+ self.insert_data_from_temp_to_target()
122
+ self.drop_table_temp_target_relation()
123
+
124
+ self.migrator_redshift_connector.target_conn.commit()
125
+ self.migrator_redshift_connector.target_conn.autocommit = True
92
126
 
93
127
  def save_to_redshift(self, operations):
94
128
  cursor = self.migrator_redshift_connector.target_conn.cursor()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maisaedu-poormans-dms
3
- Version: 1.1.73
3
+ Version: 1.1.75
4
4
  Summary: A library for making database migration tasks, for +A Education
5
5
  Home-page: UNKNOWN
6
6
  Author: A+ Educação
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="maisaedu-poormans-dms",
5
- version="1.1.73",
5
+ version="1.1.75",
6
6
  description="A library for making database migration tasks, for +A Education",
7
7
  license="MIT License",
8
8
  author="A+ Educação",