Migrate to Turso
Learn how to import your existing SQLite database to Turso.
This guide will walk you through the process of migrating your existing SQLite database to Turso Cloud. You can choose between using the Turso CLI, or the Platform API.
Preparing to Migrate
Before importing your SQLite database to Turso, you need to ensure it’s compatible with Turso’s requirements. Specifically, your SQLite database should be using WAL (Write-Ahead Logging) mode.
Open your SQLite database
Use the SQLite command-line tool or any SQLite client to open your database:
Set WAL journal mode
Run the following command to switch your database to WAL mode:
This should return wal
to confirm the change was successful.
Checkpoint and truncate the WAL file
Execute a checkpoint to ensure all changes are written to the main database file and truncate the WAL file:
Verify the journal mode
Confirm that your database is now in WAL mode:
This should return wal
.
Close the database
Exit the SQLite shell:
Your database is now ready for migration to Turso.
Using the CLI
You can create a new database from a local SQLite file using the Turso CLI:
Install the Turso CLI
Make sure you have the Turso CLI installed, and you’re authenticated.
Import your SQLite Database
Import your existing SQLite database file using the db import
command:
Your database will be named after the file (without the .db extension), and will import all your tables, data, and schema.
Connect to your database
You can now connect to your database using the shell:
Using the Platform API
You can also use the Platform API to migrate your existing SQLite database:
Signup or Login using the Turso CLI
Make sure to install the Turso CLI if you haven’t already.
Create a new Platform API Token
Now create a new API Token using the Turso CLI:
Make sure to save the token somewhere safe. You’ll need it to create a database and database token.
Retrieve your account or organization slug
The Platform API can be used with your personal account or with an organization. You’ll need the obtain the slug
of your account or organization using using the Turso CLI:
Create a Database for Import
First, create a database that’s ready to receive an import:
The seed
parameter with "type": "database_upload"
indicates that you plan to upload a database file. If you don’t proceed to upload a database, this database will count towards your quota, but will not be usable.
Create a Database Token
Generate an authentication token for your database:
This token will be used to authenticate your upload request, and future requests to the database.
Upload Your SQLite Database
Finally, upload your SQLite database file:
The Authorization
header uses the database token you generated in the
previous step, not your Platform API token.
You’re now ready to connect to your new Turso database using any of the Turso client libraries.
Was this page helpful?