-
-
Save gabrielponto/965dfd91383ab5896102b0b84d7c08db to your computer and use it in GitHub Desktop.
Script to import SQLite3 database into PostgreSQL
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
#!/bin/sh | |
# This script will migrate schema and data from a SQLite3 database to PostgreSQL. | |
# Schema translation based on http://stackoverflow.com/a/4581921/1303625. | |
# Some column types are not handled (e.g blobs). | |
SQLITE_DB_PATH=$1 | |
SQLITE_DUMP_FILE="sqlite_data.sql" | |
sqlite3 $SQLITE_DB_PATH .dump | sed -e 's/integer NOT NULL PRIMARY KEY AUTOINCREMENT/SERIAL PRIMARY KEY/g' | sed -e 's/PRAGMA foreign_keys=OFF;//' | sed -e 's/unsigned big int/BIGINT/g' | sed -e 's/UNSIGNED BIG INT/BIGINT/g' | sed -e 's/BIG INT/BIGINT/g' | sed -e 's/UNSIGNED INT(10)/BIGINT/g' | sed -e 's/BOOLEAN/SMALLINT/g' | sed -e 's/boolean/SMALLINT/g' | sed -e 's/UNSIGNED BIG INT/INTEGER/g' | sed -e 's/INT(3)/INT2/g' | sed -e 's/DATETIME/TIMESTAMP/g' | sed -e 's/datetime/TIMESTAMP/g' > $SQLITE_DUMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment