Created
July 11, 2023 06:19
-
-
Save Hosuke/a3997e9220786f5aa5a4760a254ac50f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import shutil | |
# Get current dir | |
dir_path = os.getcwd() | |
for root, dirs, files in os.walk(dir_path): | |
for file in files: | |
# Check for .sql file | |
if file.endswith('legacy.sql'): | |
# Get full file path | |
full_path = os.path.join(root, file) | |
with open(full_path) as f: | |
model_contents = f.read() | |
pattern = r'ref\(\'(\w+)\'\)' | |
model_contents = re.sub(pattern, lambda m: "ref('{}_legacy')".format(m.group(1)), model_contents) | |
# Write only to original .sql file | |
with open(full_path, 'w') as f: | |
f.write(model_contents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment