This Bash script allows you to migrate data from a PostgreSQL database into a SQLite3 database file. It creates a PostgreSQL dump file (if it doesn't already exist and a PostgreSQL connection string is provided), converts the dump file into SQLite3-compatible SQL statements, and imports the data into a new or recreated SQLite3 database file.
Before running the script, ensure that the following tools are installed on your system:
pg_dump
(PostgreSQL client utility)sed
(Stream Editor for filtering and transforming text)sqlite3
(SQLite3 command-line tool)./migrate.sh <sqlite_database_file> [postgres_connection_string] [--reset]
<sqlite_database_file>
: The path to the SQLite database file.[postgres_connection_string]
: Optional. The PostgreSQL connection string. If not provided, the script will look for an existing PostgreSQL dump file.[--reset]
: Optional. If provided, the script will reset the environment by cleaning up existing files and recreating the SQLite database.Ensure that the schema.sql
file, which defines the SQLite database schema, is present in the same directory as the migrate.sh
script before running the migration.
--reset
flag is provided, the script will remove any existing PostgreSQL dump file and SQLite3 database file, and then create a new SQLite3 database file.pg_dump
. The dump file name is derived from the SQLite database file name with the extension .dump
.sed
.BEGIN TRANSACTION
and COMMIT
statements../schema.sql
).__drizzle_migrations
table from the PostgreSQL dump. You can modify the EXCLUDE_TABLES
array in the script to include or exclude different tables.--reset
flag is provided, the script will remove any existing PostgreSQL dump file and SQLite3 database file before starting, and then create a new SQLite3 database file.migrate_postgres_to_sqlite3.log
file.To run the script unattended or in the background, you can use nohup
or &
:
nohup ./migrate.sh <arguments> &> /dev/null &
This project is licensed under the MIT License.