Created
July 26, 2024 18:16
-
-
Save itbrunoms/4b0c9114e38a7e2bd16db6e5f9b24510 to your computer and use it in GitHub Desktop.
This file contains 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 | |
def process_sql_files(directory): | |
# Percorre todos os arquivos no diretório | |
for filename in os.listdir(directory): | |
if filename.endswith(".sql"): | |
file_path = os.path.join(directory, filename) | |
# Lê o conteúdo do arquivo | |
with open(file_path, 'r', encoding='utf-8') as file: | |
content = file.read() | |
# Substitui "CREATE TABLE" por "CREATE TABLE IF NOT EXISTS" | |
new_content = content.replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS") | |
# Salva as alterações no arquivo | |
with open(file_path, 'w', encoding='utf-8') as file: | |
file.write(new_content) | |
print(f"Processed {filename}") | |
# Diretório onde os arquivos .sql estão localizados | |
sql_directory = '/caminho/para/seu/diretorio/sql' | |
# Processa os arquivos .sql no diretório especificado | |
process_sql_files(sql_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment