Skip to content

Instantly share code, notes, and snippets.

View gabrielponto's full-sized avatar

Gabriel Oliveira gabrielponto

View GitHub Profile
@gabrielponto
gabrielponto / sqlite2pg.sh
Last active February 9, 2022 21:45 — forked from eclubb/sqlite2pg.sh
Script to import SQLite3 database into PostgreSQL
#!/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
version: '3.1'
services:
postgres:
image: postgres:12.3
restart: always
environment:
POSTGRES_USER: gabriel
POSTGRES_DB: contabo
POSTGRES_PASSWORD: Contabo2019!Gabriel