Created
January 19, 2026 16:26
-
-
Save Juan-Severiano/5e2d5ef347bf92e06b812dd5b0108014 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
| #!/bin/bash | |
| # Author: Francisco Juan | |
| # Converte dump MySQL para PostgreSQL e importa | |
| # Remove migrações do Prisma e CREATE TABLE, mantém apenas INSERTs | |
| DUMP_FILE="${1:-dump.sql}" | |
| OUTPUT_FILE="dump_postgres_fixed.sql" | |
| DB_URL="${DATABASE_URL:-postgresql://user:pass@host:port?sslmode=require}" | |
| if [ ! -f "$DUMP_FILE" ]; then | |
| echo "Erro: Arquivo $DUMP_FILE não encontrado!" | |
| echo "Uso: $0 [arquivo_dump.sql]" | |
| exit 1 | |
| fi | |
| echo "Processando dump MySQL..." | |
| # Extrai apenas INSERTs, ignora _prisma_migrations e remove coisas do MySQL | |
| grep -E "^INSERT INTO" "$DUMP_FILE" | \ | |
| grep -v "_prisma_migrations" | \ | |
| sed -E \ | |
| -e 's/`([^`]+)`/\1/g' \ | |
| -e 's/\\\\"/"/g' \ | |
| -e "s/\\\\'/''/g" > "$OUTPUT_FILE" | |
| if [ ! -s "$OUTPUT_FILE" ]; then | |
| echo "Erro: Nenhum INSERT encontrado no arquivo!" | |
| exit 1 | |
| fi | |
| echo " - Arquivo processado: $OUTPUT_FILE ($(wc -l < "$OUTPUT_FILE") linhas)" | |
| echo "Importando no PostgreSQL..." | |
| docker run --rm -i \ | |
| -v "$(pwd)/$OUTPUT_FILE:/tmp/dump.sql:ro" \ | |
| -v "$(pwd)/../ca-certificate-postgreen.crt:/tmp/ca-cert.crt:ro" \ | |
| postgres:18 \ | |
| psql "$DB_URL" \ | |
| -f /tmp/dump.sql | |
| if [ $? -eq 0 ]; then | |
| echo "✅ Importação concluída com sucesso!" | |
| else | |
| echo "❌ Erro na importação!" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment