Skip to content

Comments

Update sql-dump-splitter.py#1

Open
wdetmar wants to merge 2 commits intoinspaacademy:mainfrom
wdetmar:wdetmar-patch-1
Open

Update sql-dump-splitter.py#1
wdetmar wants to merge 2 commits intoinspaacademy:mainfrom
wdetmar:wdetmar-patch-1

Conversation

@wdetmar
Copy link

@wdetmar wdetmar commented Oct 25, 2024

change to surface file names

change to surface file names
@wdetmar
Copy link
Author

wdetmar commented Oct 25, 2024

test

Changing to fix error that caused only the first file to be saved.
@wdetmar wdetmar closed this Oct 25, 2024
@davydmaker davydmaker reopened this Jan 13, 2026
@davydmaker davydmaker self-requested a review January 13, 2026 04:59
@davydmaker davydmaker added the enhancement New feature or request label Jan 13, 2026
Copy link
Member

@davydmaker davydmaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution ❤️

DEFAULT_SQL_CONDITIONS = ["DROP TABLE", "CREATE TABLE IF NOT EXISTS", "CREATE VIEW", "CREATE FUNCTION", "CREATE PROCEDURE"]

def extract_name(line):
# Regex patterns to match table/view/function/procedure names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Regex patterns to match table/view/function/procedure names

Comment on lines +17 to +27
r'CREATE TABLE (\w+)', # Match CREATE TABLE statements
r'CREATE VIEW (\w+)', # Match CREATE VIEW statements
r'CREATE FUNCTION (\w+)', # Match CREATE FUNCTION statements
r'CREATE PROCEDURE (\w+)', # Match CREATE PROCEDURE statements
r'DROP TABLE (\w+)', # Match DROP TABLE statements
]

for pattern in patterns:
match = re.search(pattern, line)
if match:
return match.group(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By enhancing the regex, we can support variations in spacing, IF NOT EXISTS statements, names with/without quotes, and case sensitivity:

Suggested change
r'CREATE TABLE (\w+)', # Match CREATE TABLE statements
r'CREATE VIEW (\w+)', # Match CREATE VIEW statements
r'CREATE FUNCTION (\w+)', # Match CREATE FUNCTION statements
r'CREATE PROCEDURE (\w+)', # Match CREATE PROCEDURE statements
r'DROP TABLE (\w+)', # Match DROP TABLE statements
]
for pattern in patterns:
match = re.search(pattern, line)
if match:
return match.group(1)
r'CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:`?(\w+)`?|"(\w+)"|\'(\w+)\')',
r'CREATE\s+VIEW\s+(?:`?(\w+)`?|"(\w+)"|\'(\w+)\')',
r'CREATE\s+FUNCTION\s+(?:`?(\w+)`?|"(\w+)"|\'(\w+)\')',
r'CREATE\s+PROCEDURE\s+(?:`?(\w+)`?|"(\w+)"|\'(\w+)\')',
r'DROP\s+TABLE\s+(?:`?(\w+)`?|"(\w+)"|\'(\w+)\')',
]
for pattern in patterns:
match = re.search(pattern, line, re.IGNORECASE)
if match:
return next((g for g in match.groups() if g), None)

current_content = []
condition_hit_count = 0
if current_content:
# Save the current content to the previous file name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Save the current content to the previous file name

save_file(current_content, output_dir, current_file_name)
file_count += 1

# Set the new file name based on the extracted name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Set the new file name based on the extracted name

file_count += 1

# Set the new file name based on the extracted name
current_file_name = name if name else f"file_{file_count}" # Fallback if name extraction fails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
current_file_name = name if name else f"file_{file_count}" # Fallback if name extraction fails
current_file_name = name if name else f"file_{file_count}"

Comment on lines +81 to +82
current_content = [] # Reset current content for the new file
condition_hit_count = 0 # Reset hit count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
current_content = [] # Reset current content for the new file
condition_hit_count = 0 # Reset hit count
current_content = []
condition_hit_count = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants