Ir al contenido principal

migrar access a postgres

aca hay un pequeño script que hice para migrar de access a postgres, tuve que hacer algunos trucos para que ande bien. si a alguien le sirve...

import os
import commands

archivo = "archivo.mdb"

tables = commands.getoutput("mdb-tables -S %s" % (archivo,))
os.popen("rm carga.sql")
os.popen("rm schema.sql")

os.popen("mdb-schema -S %s postgres| sed 's/Postgres_Unknown 0x0c/Text/' | grep \"\-\-\" -v | grep \"^DROP TABLE\" -v | sed 's/Bool/Int8/' > schema.sql" \
% (archivo,))

for table in tables.split():
cmd = \
# si tenes el postgres con locales que te pide insertar la fecha con un
# formato no ISO (MDY) correr la siguiente linea antes de los inserts
# SET DateStyle TO 'MDY';
"mdb-export -I -S %s %s | sed -e 's/)$/)\;/' | sed -e s/\\\"/\\'/g >> carga.sql"
if not table.startswith('MSys'):
os.popen(cmd % (archivo, table))

Comentarios

Comments powered by Disqus