Coming from other databases

Coming from SQLite

How to move from an embedded SQLite file to a Raft DB server with a MySQL or PostgreSQL driver, what differs in dialect and typing, and what you give up (running inside the application).

SQLite is a library inside your program; Raft DB is a server. The move is worth it when several programs or machines need the same data, when you want replication, or when one file is no longer enough. It is not worth it for a single-user program that benefits from having no server at all.

Choose a dialect#

Use the MySQL or MariaDB front-end (port 3306) or the PostgreSQL front-end (port 5432), whichever driver your language already has. Neither dialect is identical to SQLite's, so expect to edit some statements.

What changes#

SQLiteRaft DB through a SQL front-end
Any column holds any type (dynamic typing)Columns have types and values are checked; define the types
INTEGER PRIMARY KEY is the row idAUTO_INCREMENT (MySQL dialect) or a sequence / identity (PostgreSQL dialect)
datetime('now'), strftimeNOW(), DATE_FORMAT (MySQL) or to_char (PostgreSQL)
PRAGMA ...server settings; most pragmas have no equivalent
INSERT OR REPLACEREPLACE INTO or INSERT ... ON DUPLICATE KEY UPDATE (MySQL dialect)
Foreign keys off unless enabledenforced when declared
One writer at a time (file lock)many sessions; isolation is per table at READ-COMMITTED
`

Moving the data#

  1. sqlite3 app.db .dump > app.sql gives a SQL script in SQLite's dialect. Edit the CREATE TABLE statements to real types and remove PRAGMA, BEGIN TRANSACTION/COMMIT lines and sqlite_sequence rows.
  2. Load it with mysql or psql against Raft DB, or export each table as CSV (.mode csv) and use LOAD DATA or COPY.
  3. Compare row counts table by table, and run the application's test suite against the new connection string.

What you give up#

The program no longer owns its data file: there is a server to install, secure and keep running. In exchange, several applications can share the data, it can be replicated, and the Studio and the tools can look at it.