pgloader icon indicating copy to clipboard operation
pgloader copied to clipboard

Import multiple sqlite3 files as schemas

Open talvasconcelos opened this issue 3 years ago • 2 comments

Hi, I'm trying to find out a way to import a few .sqlite3 files (i have a bunch of separated db) into postgres. What I'd like to achieve is to have some data on the public schema (my main database.sqlite3) and add all other .sqlite3 files each with it's own schema.

Can I use pgloader for this? I was thinking of maybe a bash script, that looped for the sqlite3 files and did: pgloader ./test/sqlite/sqlite_a.sqlite3 postgresql:///newdb.a - is this possible?

maybe the bash could be something like: `#!/bin/bash

createdb newdb pgloader ./test/sqlite/database.sqlite3 postgresql:///newdb for file in $files do pgloader ./test/sqlite/$file.sqlite3 postgresql:///newdb.$file done ` Is there an easier way of pulling this off? This is a one time deal, as users would do it once to migrate their data from sqlite to postgres on my app!

talvasconcelos avatar Aug 03 '21 15:08 talvasconcelos

#!/bin/bash

Create the main PostgreSQL database

createdb newdb

List of SQLite files

files=("database" "sqlite_a" "sqlite_b") # Add more file names as needed

Loop through the SQLite files and migrate them to separate schemas

for file in "${files[@]}" do

Create a new schema in PostgreSQL

psql -d newdb -c "CREATE SCHEMA newdb_$file"

Migrate data from SQLite to PostgreSQL with pgloader

pgloader "./test/sqlite/${file}.sqlite3" "postgresql:///newdb?schema=newdb_$file" done

ljluestc avatar Sep 30 '23 05:09 ljluestc

#!/bin/bash

Create the main PostgreSQL database

createdb newdb

List of SQLite files

files=("database" "sqlite_a" "sqlite_b") # Add more file names as needed

Loop through the SQLite files and migrate them to separate schemas

for file in "${files[@]}" do

Create a new schema in PostgreSQL

psql -d newdb -c "CREATE SCHEMA newdb_$file"

Migrate data from SQLite to PostgreSQL with pgloader

pgloader "./test/sqlite/${file}.sqlite3" "postgresql:///newdb?schema=newdb_$file" done

That dosen't work

s-nt-s avatar Dec 16 '23 03:12 s-nt-s