Migrate your database
You can migrate databases between different versions of Kùzu without manually writing DDL and COPY statements.
To perform a migration, you would first export the database from an existing Kùzu version using the command EXPORT DATABASE
.
Then, you would import this database into another Kùzu version using IMPORT DATABASE
.
Export database
The EXPORT DATABASE
command exports all the contents of a Kùzu database to the specified directory.
The command generates the following files under the /path/to/export
directory, which
are needed to be able to import this database to a new Kùzu version:
schema.cypher
: Contains the definitions of all node and edge tables.macro.cypher
: Includes the definitions of all macro functions.copy.cypher
: ContainsCOPY FROM
statements for reimporting data.Data files
: These files contain the actual database data (in CSV or Parquet format).
The parameters for EXPORT DATABASE
are the same as those used
when running COPY TO
statements. The example below shows how to export a database using default configurations.
EXPORT DATABASE '/path/to/export'
The default behaviour is to export the data tables to Parquet format. This is done to reduce scope of formatting errors and to improve performance. You can use the format
parameter to output to other formats, for e.g. CSV.
The format
parameter can either be csv
or parquet
.
Here’s an example of how to export a database using the CSV format for data files.
EXPORT DATABASE '/path/to/export' (format="csv", header=true);
Import database
The IMPORT DATABASE
command imports the contents of the database from a specific directory to which
a Kùzu database was exported to using EXPORT DATABASE
command. Under the hood, this command uses the
Cypher and data files that were created by the EXPORT DATABASE
command to recreate the necessary databases
and tables in the new Kùzu version you are migrating to.
The query below imports the database from a directory named /path/to/export
to
the current database directory that your session points to:
IMPORT DATABASE '/path/to/export';