Git Product home page Git Product logo

mysql-postgresql-converter's Introduction

MySQL to PostgreSQL Converter

Lanyrd's MySQL to PostgreSQL conversion script. Use with care.

This script was designed for our specific database and column requirements - notably, it doubles the lengths of VARCHARs due to a unicode size problem we had, places indexes on all foreign keys, and presumes you're using Django for column typing purposes.

GitLab-specific changes

The gitlab branch of this fork contains the following changes made for GitLab.

  • Guard against replacing '0000-00-00 00:00:00' inside SQL text fields.
  • Replace all MySQL zero-byte string literals \0. This is safe as of GitLab 6.8 because the GitLab database schema contains no binary columns.
  • Never set 'NOT NULL' constraints on datetimes.
  • Drop sequences before creating them.
  • Preserve default values of boolean (originally tinyint(1)) columns.
  • Import all indexes.
  • Import index names.
  • Drop tables before creating.
  • Drop indexes before creating.

How to use

First, dump your MySQL database in PostgreSQL-compatible format

mysqldump --compatible=postgresql --default-character-set=utf8 \
-r databasename.mysql -u root gitlabhq_production -p

Then, convert it using the dbconverter.py script.

python db_converter.py databasename.mysql databasename.psql

It'll print progress to the terminal

Now we have a DB dump that can be imported but the dump will be slow due to existing indexes. We use 'ed' to edit the DB dump file and move the 'DROP INDEX' statements to the start of the import. Ed is not the fastest tool for this job if your DB dump is multiple gigabytes. (Patches to the converter are welcome!)

ed -s databasename.psql < move_drop_indexes.ed

Next, load your new dump into a fresh PostgreSQL database using:

psql -f databasename.psql -d gitlabhq_production

More information

You can learn more about the move which this powered at http://lanyrd.com/blog/2012/lanyrds-big-move/ and some technical details of it at http://www.aeracode.org/2012/11/13/one-change-not-enough/.

mysql-postgresql-converter's People

Contributors

jacobvosmaer avatar andrewgodwin avatar stefl avatar antonpirker avatar bbodenmiller avatar douwem avatar squarepegsys avatar tominsam avatar pelme avatar dzaporozhets avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.