Skip to content

Commit

Permalink
update script to also display date
Browse files Browse the repository at this point in the history
reformat
  • Loading branch information
amishas157 committed Oct 30, 2024
1 parent 0021160 commit 60aeb0a
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions scripts/get_source_data_schema_changelog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
from datetime import datetime

old_schemas_dir = "original_schemas"
new_schemas_dir = "new_schemas"
Expand All @@ -23,15 +24,7 @@ def read_json_file(filepath):
tables_removed = [model for model in old_schemas if model not in new_schemas]
common_tables = [model for model in new_schemas if model in old_schemas]

if tables_added:
print("")
print("## Tables Added:")
print([table for table in tables_added])

if tables_removed:
print("")
print("## Tables Removed:")
print([table for table in tables_removed])
schema_changes = {}

for schema in common_tables:
old_file_path = os.path.join(old_schemas_dir, schema + '_schema.json')
Expand All @@ -50,16 +43,52 @@ def read_json_file(filepath):
if name in old_dict and new_dict[name]['type'] != old_dict[name]['type']
]

if added or deleted or type_changed:
print("")
print(f"## {schema}")

if added:
print(f'**Added columns:** {[field for field in added]}')
if schema not in schema_changes:
schema_changes[schema] = {}
schema_changes[schema]['added'] = added

if deleted:
print(f'**Deleted columns:** {[field for field in deleted]}')
if schema not in schema_changes:
schema_changes[schema] = {}
schema_changes[schema]['deleted'] = deleted

if type_changed:
for (field, new_type, old_type) in type_changed:
print(f'Type changed for column {field} from {old_type} to {new_type}')
if schema not in schema_changes:
schema_changes[schema] = {}
schema_changes[schema]['type_changed'] = type_changed

if tables_added or tables_removed or schema_changes:
today = datetime.now()
formatted_date = today.strftime("%Y-%m-%d")
print(formatted_date)

if tables_added:
print("")
print("## Tables Added:")
print([table for table in tables_added])

if tables_removed:
print("")
print("## Tables Removed:")
print([table for table in tables_removed])

if schema_changes:
print("")
print("## Schema Changes:")

for schema in schema_changes:
print("")
print(schema)
for operation_type in schema_changes[schema]:
data = schema_changes[schema][operation_type]
if operation_type == 'added':
print("")
print(f'**Added columns:** {[field for field in data]}')
elif operation_type == 'deleted':
print("")
print(f'**Deleted columns:** {[field for field in data]}')
elif operation_type == 'type_changed':
for (field, new_type, old_type) in data:
print("")
print(f'**Type changed** for column {field} from {old_type} to {new_type}')

0 comments on commit 60aeb0a

Please sign in to comment.