pgloader
pgloader copied to clipboard
Import multiple sqlite3 files as schemas
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!
#!/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
#!/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