Code Monkey home page Code Monkey logo

mssql2pg's Introduction

mssql2pg

Database conversion script from MS SQL Server to PostgreSQL.

  • The script works from command line.
  • Runs in python 2.x or 3.x
  • Produces a SQL script similar to PostgreSQL default backup to create database, all objects and import data.
    • Data import is done via quick COPY command, not individual inserts
    • Just use psql -f FILE_NAME to create a database after script ran.
    • Converts “dbo” schema objects to “public”, no “dbo” schema will be created in PostgreSQL
    • Example of such a script is below.
  • Converts types from SQL Server to PostgreSQL
  • Generates sequences for IDENTITY fields
  • Scripts outputs progress, so you don’t need to guess if it’s working or froze up.

##Dependencies

  • FreeTDS
  • pymssql
  • sqlalchemy

##Automatically Generated Usage Message

usage: mssql2pg.py [-h] [-p PASSWORD] [-d DESTINATION_DATABASE]
                   [-f OUTPUT_FILE_NAME] [-u] [-n RECORD_COUNT]
                   [-x EXCLUDE_SCHEMAS]
                   host_name database_name login_name

Convert Microsoft SQL Server database into PostgreSQL. Produces .sql script
that can be executed with psql.

positional arguments:
  host_name             SQL Server host name
  database_name         Source database name
  login_name            Login name

optional arguments:
  -h, --help            show this help message and exit
  -p PASSWORD, --password PASSWORD
                        Password for the login_name
  -d DESTINATION_DATABASE, --destination-database DESTINATION_DATABASE
                        If not provided, destination database name will be the
                        same as source.
  -f OUTPUT_FILE_NAME, --file OUTPUT_FILE_NAME
                        If not provided, script will be printed to standard
                        output.
  -u, --underscore      Convert CamelCase into underscored_identifiers
                        (schemas, tables and columns).
  -n RECORD_COUNT, --limit_records RECORD_COUNT
                        For test runs, process only provided number of records
                        per table. WARNING: foreign keys may not import
                        properly.
  -x EXCLUDE_SCHEMAS, --exclude-schemas EXCLUDE_SCHEMAS
                        Comma separated (no spaces) list of schemas that will
                        be excluded from export. If not provided, all schemas
                        will be processed.

##Example:

python3 mssql2pg.py SqlServer PgConversionExample user1 p4ssw0rd -f example.sql -d conversion_example -u

##Output:

--
-- PREPARE DATABASE

\connect postgres
drop database ubt;
create database ubt;
\connect ubt

CREATE EXTENSION "uuid-ossp";
        
--
-- CREATING SEQUENCES
CREATE SEQUENCE ourfurnature_seq;

--
-- CREATE TABLES
CREATE TABLE ourfurnature (
    id INT NOT NULL DEFAULT nextval('ourfurnature_seq'),
    name VARCHAR(50)
);
ALTER TABLE ourfurnature ADD PRIMARY KEY (id);

--
-- INSERT DATA
\echo
\echo Importing table [ourfurnature]
\echo
COPY ourfurnature (id, name) FROM stdin;
1	table
2	chair
3	bed
\.

--
-- UPDATING SEQUENCE START VALUES
ALTER SEQUENCE ourfurnature_seq START WITH 4;

mssql2pg's People

Contributors

mzarnitsa 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.