Skip to content

Commit ffd6101

Browse files
authored
Add database export and import documentation (#940)
## Goal Introduce database export and import documentation with an extended migration guide between TypeDB 2.x and TypeDB 3.x. ## Implementation Fill the database export / import page with theory and usage details. Redesign the 2.x to 3.x migration manual to have multiple pages: * index for the introduction; * a separate page for differences between 2.x and 3.x; * a separate page with the migration guide and a detailed example to work with different errors occurring along the way.
1 parent 454f09b commit ffd6101

File tree

12 files changed

+549
-52
lines changed

12 files changed

+549
-52
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
= Export and import
2+
:page-aliases: {page-version}@manual::configuring/export.adoc, {page-version}@manual::configuring/import.adoc, {page-version}@manual::configuring/import_export.adoc
3+
4+
In this guide, you'll see how to export and import the schema and data of a TypeDB database.
5+
6+
[IMPORTANT]
7+
====
8+
This feature is introduced in TypeDB 3.4.0. If you want to export or import a database from earlier versions of TypeDB 3.x, simply update your server and client and follow this manual.
9+
10+
You can import your databases exported from TypeDB 2.x following xref:{page-version}@manual::migration/2_to_3/process.adoc[this guide].
11+
====
12+
13+
== Understanding export and import
14+
15+
TypeDB database can be represented as two files:
16+
17+
[#_files]
18+
1. A text file with its TypeQL schema description: a complete xref:{page-version}@manual::schema/schema_structure.adoc[`define` query] for the whole schema.
19+
2. A binary file with its data.
20+
21+
An exported database can be imported into another version of TypeDB using these two files.
22+
This is the best tool you can use to migrate a database between two incompatible versions of TypeDB (e.g., a migration xref:{page-version}@manual::migration/2_to_3/process.adoc[from TypeDB 2.x to TypeDB 3.x]).
23+
24+
Both operations are performed through the network, but the server and the client can be used on the same host.
25+
26+
Examples below use xref:{page-version}@manual::tools/console.adoc[TypeDB Console] as the most accessible client for these operations.
27+
Please check the xref:{page-version}@drivers::index.adoc[Drivers API references] to explore available programmatic commands (e.g., xref:{page-version}@drivers::rust/api-reference.adoc[Rust]).
28+
29+
[#_export]
30+
== Export
31+
32+
Database export allows a client to download xref:#_files[database schema and data files] from a TypeDB server for future import to the same or higher TypeDB version.
33+
34+
The files are created on the client side.
35+
The exported binary file might be up to two times larger than the original database.
36+
If the client connects to a remote host, the server's disk remains unchanged, thus introducing zero risks to the stability of the server.
37+
Please ensure the client's disk has enough free capacity to store a file of this size.
38+
39+
While the database data is being exported, parallel queries are allowed, but none of them will affect the exported data thanks to TypeDB's xref:{page-version}@manual::queries/transactions.adoc[transactionality].
40+
However, the database will not be available for such operations as deletion.
41+
42+
[NOTE]
43+
====
44+
The files can be incomplete and corrupted if the export operation is interrupted by user.
45+
====
46+
47+
=== Perform through TypeDB Console
48+
49+
1. Make sure that your TypeDB Server is running.
50+
51+
2. Follow xref:{page-version}@manual::tools/console.adoc[this guide] for TypeDB Console set up and connection.
52+
53+
3. Execute `database export database-name schema.typeql data.typedb`, where
54+
55+
- `database-name` is the name of the exported database;
56+
- `schema.typeql` is the exported schema definition file path;
57+
- `data.typedb` is the exported data file path.
58+
59+
4. The result (either `Successfully exported database` or an error) will be printed to the Console.
60+
61+
== Import
62+
63+
Database import allows a client to upload previously exported xref:#_files[database schema and data files] to a TypeDB server.
64+
65+
For your safety, the imported database should not exist on the target server.
66+
It is possible to assign any new name to the imported database.
67+
68+
[NOTE]
69+
====
70+
The database will be incomplete (and thus not recommended for usage) if the import operation is interrupted.
71+
It is expected to be automatically removed from the disk, but a small number of unexpected technical issues can prevent this from happening.
72+
A server restart will resolve any related issues.
73+
====
74+
75+
=== Perform through TypeDB Console
76+
77+
1. Make sure that your TypeDB Server is running.
78+
79+
2. Follow xref:{page-version}@manual::tools/console.adoc[this guide] for TypeDB Console set up and connection.
80+
81+
3. Execute `database import database-name schema.typeql data.typedb`, where
82+
83+
- `database-name` is the new name of the imported database;
84+
- `schema.typeql` is the imported schema definition file path;
85+
- `data.typedb` is the imported data file path.
86+
87+
4. The result (either `Successfully imported database` or an error) will be printed to the Console.
88+
89+
== Troubleshooting
90+
91+
Follow this checklist if any errors occur:
92+
93+
* Ensure that you use xref:{page-version}@manual::tools/console.adoc#version-compatiblity[compatible] TypeDB Server and TypeDB Console.
94+
* Ensure that the correct file paths were specified for the operations.
95+
* Ensure that the schema has been imported correctly to the new database.
96+
Use xref:{page-version}@manual::studio.adoc[TypeDB Studio] or xref:{page-version}@manual::console.adoc[TypeDB Console] to check the schema after import.
97+
* If you import a TypeDB 2.x database, some errors may be expected.
98+
Check out xref:{page-version}@manual::migration/2_to_3/process.adoc[this page] for a detailed guide.
99+
100+
If any errors persist, please join one of our communities and ask for assistance.

manual/modules/ROOT/pages/maintenance/exports.adoc

Lines changed: 0 additions & 6 deletions
This file was deleted.

manual/modules/ROOT/pages/maintenance/import_export.adoc

Lines changed: 0 additions & 7 deletions
This file was deleted.

manual/modules/ROOT/pages/migration/2_to_3.adoc renamed to manual/modules/ROOT/pages/migration/2_to_3/diff.adoc

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
1-
= TypeDB 2.x to 3.x
2-
3-
TypeDB 3.x is a major leap forward, offering significantly improved performance and introducing a wide range of changes across almost every aspect of the database.
4-
This page outlines the key updates you should know, alongside recommendations for server and driver upgrades.
5-
6-
== Migration process
7-
8-
1. **Review the <<_temporarily_missing, missing features>> list** before starting your migration.
9-
Some features might not yet be available in 3.0, and you may need to wait for a newer version to proceed.
10-
1. **Understand the scope of changes** by referring to the <<_major_changes, major changes>> section.
11-
1. **Export your schema and data** from TypeDB 2.x using the xref:2.x@manual::configuring/export.adoc[export manual].
12-
1. **Data migration guide and tools are in progress.** Full migration of a production database is currently unsupported. **Stay tuned for updates!**
13-
1. *(Optional)* Refresh your knowledge of TypeDB and TypeQL by following the updated xref:{page-version}@home::quickstart.adoc[Quickstart Guide].
14-
1. **Set up TypeDB 3.0** by following the xref:{page-version}@manual::configure/index.adoc[Configuration Manual].
15-
The setup process remains largely unchanged from 2.x.
16-
1. **Manually update your schema definition file.** Use error messages during application to guide adjustments.
17-
The <<_major_changes, major changes>> section highlights the most common updates needed.
18-
- Rewrite rules in your schema as functions.
19-
Refer to the xref:{page-version}@typeql::functions/index.adoc[Functions Documentation] and xref:{page-version}@manual::schema/functions.adoc[Manual] for guidance on the new abstraction model.
20-
1. *(Optional)* Update your supporting queries using the xref:{page-version}@manual::schema/index.adoc[Schema] and xref:{page-version}@manual::CRUD/index.adoc[CRUD] manuals.
21-
1. *(Optional)* Update your drivers.
22-
Consult the xref:{page-version}@drivers::index.adoc[Drivers Manual] and the <<_major_changes_drivers, major driver changes>> list for details.
23-
24-
[#_major_changes]
25-
== Major changes
1+
= TypeDB 2.x to TypeDB 3.x: what's changed
2+
3+
This page outlines the key updates of TypeDB 3.x compared to 2.x you should be aware of while transitioning between these versions.
264

275
[NOTE]
286
====
29-
This section highlights **changes from TypeDB 2.x**, not all new features in 3.0. Explore the xref:{page-version}@manual::index.adoc[Manual], xref:{page-version}@typeql::index.adoc[TypeQL Documentation], and https://github.com/typedb/typedb/releases[release notes] for the full picture.
7+
This section highlights **changes from TypeDB 2.x**, not all new features in 3.x.
8+
Explore the xref:{page-version}@manual::index.adoc[Manual], xref:{page-version}@typeql::index.adoc[TypeQL Documentation], and https://github.com/typedb/typedb/releases[release notes] for the full picture.
309
Stay tuned for upcoming blogs showcasing new features!
3110
====
3211

3312
Click on a feature below for detailed documentation and examples.
3413

35-
=== TypeDB and TypeQL
14+
== TypeDB and TypeQL
3615

3716
* **Sessions Removed:** Connections to TypeDB now only require opening a `schema`, `write`, or `read` xref:{page-version}@manual::queries/transactions.adoc[transaction].
3817
* **Integer Value Type Renamed:** `long` is now xref:{page-version}@typeql::values/integer.adoc[`integer`].
@@ -61,9 +40,10 @@ Explicitly define cardinalities for traits expecting multiple instances to avoid
6140
* **Rules and Inference Replaced:** Rules are now replaced by xref:{page-version}@typeql::functions/index.adoc[functions], requiring explicit functions execution instead of inference, but offering more abstraction and flexibility.
6241

6342
[#_major_changes_drivers]
64-
=== TypeDB Drivers
43+
== TypeDB Drivers
6544

6645
**API Simplification** for smoother UX and better maintenance.
46+
Visit the xref:{page-version}@drivers::index.adoc[Drivers manual] to access their full documentation.
6747

6848
- Now, all schema and data fetching and modifications are performed through a single `transaction.query("your query")` interface.
6949
- No more `query().insert()` and `query().define()`.
@@ -80,21 +60,15 @@ Take into account that some of your processes can be blocked if you previously r
8060

8161
=== TypeDB and TypeQL
8262

83-
* Database import and export tools.
84-
* Configuration files (use CLI as a temporary solution).
8563
* Instantiation restriction for inherited `owns` and `plays` (used to `as`).
86-
A better way is planned to be released in the future (NOTE: you don't need the `as` keyword to <<#_specialize, specialize>> an ownership of an inherited super attribute type with an ownership of its subtype).
64+
An enhanced approach is in development (NOTE: you don't need the `as` keyword to <<#_specialize, specialize>> an ownership of an inherited super attribute type with an ownership of its subtype, but you cannot "hide" the original definition from inheritance).
8765
* Scaling support for Cloud and Enterprise editions.
8866

8967
=== TypeDB Drivers
9068

9169
* Node.js, C, C++, and C# drivers are not yet available.
9270
Consider using one of xref:{page-version}@drivers::index.adoc[the available languages] or xref:{page-version}@drivers::http/index.adoc[the HTTP Endpoint].
9371

94-
=== TypeDB Studio
95-
96-
* **Graph visualizer** and **Type browser** are temporarily unavailable, but will be reimplemented and enhanced in the new TypeDB Studio soon.
97-
9872
[#_having_troubles]
9973
== Having troubles?
10074

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
= TypeDB 2.x to TypeDB 3.x
2+
3+
TypeDB 3.x is a major leap forward, offering significantly improved performance and introducing a wide range of changes across almost every aspect of the database.
4+
5+
These pages outline the key changes and upgrade instructions to make your migration from an older version of TypeDB as smooth as possible.
6+
7+
[cols-2]
8+
--
9+
.xref:{page-version}@manual::migration/2_to_3/diff.adoc[]
10+
[.clickable]
11+
****
12+
Explore all main changes between the two major versions of TypeDB.
13+
****
14+
15+
.xref:{page-version}@manual::migration/2_to_3/process.adoc[]
16+
[.clickable]
17+
****
18+
Upgrade TypeDB 2.x to TypeDB 3.x following a step-by-step guide.
19+
****
20+
--
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
= TypeDB 2.x to TypeDB 3.x: migration process
2+
3+
This page gives recommendations for server and driver upgrades between the two major versions of TypeDB, as well as a step-by-step example of such a migration.
4+
5+
== Migration plan
6+
7+
1. **Understand the scope of changes** by referring to the xref:{page-version}@manual::migration/2_to_3/diff.adoc[major changes] page.
8+
1. **Review the xref:{page-version}@manual::migration/2_to_3/diff.adoc#_temporarily_missing[missing features] list** before starting your migration.
9+
Some features might not yet be available in 3.x, and you may need to wait for a newer version to proceed.
10+
1. *(Optional)* Refresh your knowledge and adjust to the new versions of TypeDB and TypeQL by following the updated xref:{page-version}@home::quickstart.adoc[Quickstart Guide].
11+
1. **Set up TypeDB 3.x** by following the xref:{page-version}@manual::configure/index.adoc[Configuration Manual].
12+
1. **Migrate your TypeDB 2.x database** following the xref:#_step_by_step[step-by-step instructions below].
13+
The setup process remains largely unchanged from 2.x.
14+
1. *(Optional)* Update your supporting queries using the xref:{page-version}@manual::schema/index.adoc[Schema] and xref:{page-version}@manual::CRUD/index.adoc[CRUD] manuals.
15+
1. *(Optional)* Update your drivers.
16+
Consult the xref:{page-version}@drivers::index.adoc[Drivers Manual] and the xref:{page-version}@manual::migration/2_to_3/diff.adoc#_major_changes_drivers[major driver changes] list for details.
17+
18+
[#_step_by_step]
19+
== Step-by-step example
20+
21+
This section showcases a step-by-step example of migrating a database between TypeDB 2.x and TypeDB 3.x using xref:{page-version}@manual::maintenance/export_import.adoc[major changes][export and import].
22+
23+
This example uses a database called `social-network`.
24+
It contains an arbitrary set of data and the 2.x schema provided below.
25+
26+
[#_schema_reference]
27+
.social-network's 2.x schema
28+
[%collapsible]
29+
====
30+
.social-network.typeql
31+
[,typeql]
32+
----
33+
include::{page-version}@manual:resources:partial$migration/2_to_3/schema-2x.tql[tag=full-query]
34+
----
35+
====
36+
37+
[#_prepare_data]
38+
=== Optional: resolve data conflicts
39+
40+
While most of the changes in TypeDB 3.x affect only the schema, there is also one very important change in data, which can lead to errors on the <<_import, import stage>> of this guide.
41+
42+
**Attributes can no longer own attributes** in TypeDB 3.x.
43+
If your data contains attributes owning attributes, you will see an error like:
44+
45+
[source]
46+
----
47+
Invalid migration item received: attributes cannot own attributes in this version of TypeDB (deprecated).
48+
----
49+
50+
In this situation, an additional step is required before proceeding, and it will require modifications of the original 2.x's database.
51+
52+
==== Move attributed owned by attributes
53+
54+
This is an example of migration of attributes owned by attributes for the <<_schema_reference, referenced schema>>.
55+
56+
Our goal is to move `bio-version` from `bio` to `page` owning the `bio` attributes.
57+
This way, both `bio` and `bio-version` will be attached to the same entity (note that it's only one of the ways to redesign this schema).
58+
59+
First, using a schema write transaction, define the additional required trait of `page`:
60+
61+
[,typeql]
62+
----
63+
include::{page-version}@manual:resources:partial$migration/2_to_3/attribute-migration-queries.tql[tag=step1-define-entity-ownership]
64+
----
65+
66+
Then, using a data write transaction, perform the data moving between `bio`s and `page`s:
67+
68+
[,typeql]
69+
----
70+
include::{page-version}@manual:resources:partial$migration/2_to_3/attribute-migration-queries.tql[tag=step2-move-data]
71+
----
72+
73+
Finally, verify that the data is moved correctly.
74+
As an additional step of verification, you can try undefining the original ownership to verify that it's now redundant:
75+
76+
[,typeql]
77+
----
78+
include::{page-version}@manual:resources:partial$migration/2_to_3/attribute-migration-queries.tql[tag=step3-undefine-attribute-ownership]
79+
----
80+
81+
Now your data is ready to get migrated to TypeDB 3.x!
82+
83+
[#_export]
84+
=== Export the database from TypeDB 2.x
85+
86+
Use xref:2.x@manual::configuring/export.adoc#_export[2.x export] to export your TypeDB 2.x database as a schema definition file and a data file.
87+
88+
While your server is running, execute `typedb server export` using the same server binary:
89+
90+
[source,console]
91+
----
92+
typedb server export --database=social-network --port=1729 --schema=social-network.typeql --data=social-network.typedb
93+
----
94+
95+
[#_prepare_schema]
96+
=== Prepare the new schema
97+
98+
**Manually update your schema definition file.**
99+
100+
- The xref:{page-version}@manual::migration/2_to_3/diff.adoc[major changes] page highlights the most common updates needed.
101+
- For simplicity, rules can be completely removed.
102+
Additional queries can be run to define functions as their replacements later.
103+
104+
This step can require a couple of iterations until you reach the final state of your new schema you will be satisfied with.
105+
Use error messages during application to guide adjustments.
106+
107+
This is a sample example of the updated ``social-network``'s schema, written in TypeQL 3.x:
108+
109+
.social-network's 3.x schema
110+
[%collapsible]
111+
====
112+
.social-network-3x.typeql
113+
[,typeql]
114+
----
115+
include::{page-version}@manual:resources:partial$migration/2_to_3/schema-3x.tql[tag=full-query]
116+
----
117+
118+
Noticeable highlights:
119+
120+
- Attribute types can be subtyped even if they are not abstract.
121+
- Attributes can no longer own attributes.
122+
See `bio-version` for an example of such redesign.
123+
- `long` is now `integer`.
124+
- We can restrict cardinalities of `relates`, `owns`, and `plays` using the `@card` annotation.
125+
Default cardinality values protect your data, but they may not suite your needs. Consider overriding them explicitly.
126+
- We can redeclare traits like `owns` on subtypes to put additional constraints on them.
127+
- While there are no `as` keyword for `owns` and `plays`, in most cases, like ours, it's not needed.
128+
E.g., the previously overridden `owns id` does not require overriding in 3.x as it's an ownership of an abstract attribute, so it cannot be instantiated without type specialization (e.g., `owns post-id`).
129+
- More constraints can be moved from your application logic to the schema: see the implication of `@values`, an enum-like constraint of TypeQL.
130+
131+
If you want to put data constraints, but your data does not yet satisfy them, you can start with a relaxed schema and then add the constraints required via additional `define` queries.
132+
====
133+
134+
[#_import]
135+
=== Import the database into TypeDB 3.x
136+
137+
Launch a xref:{page-version}@manual::install/index.adoc[TypeDB 3.x server] and connect to it using a compatible xref:{page-version}@manual::tools/console.adoc[TypeDB Console].
138+
139+
In TypeDB Console, execute a `database import` command:
140+
141+
[source,console]
142+
----
143+
database import social-network /path-to-updated-schema/social-network-3x.typeql /path-to-2.x-export/social-network.typedb
144+
----
145+
146+
[NOTE]
147+
====
148+
You can operate other server's databases without restrictions while the new database is being imported.
149+
====
150+
151+
In case of successful migration, you will see:
152+
153+
[source]
154+
----
155+
Successfully imported database.
156+
----
157+
158+
Otherwise, a descriptive error will be shown.
159+
After fixing this error, retry the same command.
160+
161+
[#_after_import]
162+
=== After import
163+
164+
From this point, your database is completely functional.
165+
Its schema and data are synchronized and technically correct.
166+
167+
We recommend running a few read queries to verify that the migration was logically successful and familiarize yourself with the updated TypeQL and your new schema.
168+
169+
If necessary, define TypeQL functions and update any queries that previously relied on the removed rules to use the new functions instead.
170+
171+
Visit xref:{page-version}@manual::migration/2_to_3/diff.adoc[] and xref:{page-version}@manual::index.adoc[] to learn more about TypeDB 3.x.
172+
Enjoy your journey!
173+
174+
[#_having_troubles]
175+
== Having troubles?
176+
177+
For troubleshooting tips and guidance, refer to the xref:{page-version}@manual::troubleshooting/index.adoc[Troubleshooting Manual].

0 commit comments

Comments
 (0)