migrado
v1.0.6
Published
ArangoDB migrations and batch processing manager
Downloads
21
Readme
Migrado
🥑 ArangoDB migrations and batch processing manager.
migrado is a command-line client that can help build and run schema or data migrations against your ArangoDB instance.
migrado utilizes ArangoDB Transactions when running data migrations to ensure failed scripts are rolled back automatically. arangosh from the ArangoDB Client Tools is required to run schema migrations, however no transaction safety is available at this point.
migrado should be considered alpha software. Make sure you test well before using in a production setting.
If you have trouble, open an issue. Contributions are welcome.
Installation
migrado requires Node.js 12 or higher.
$ yarn add migrado
or
$ npm install -s migrado
Data migrations
You need to declare all collections subject to write operations using the syntax // write collection_name
, because ArangoDB needs this information for locking during transactions. We've made the declaration explicit to reduce errors. Attempting to write to collections not declared in this way will cause the migration to fail.
In general, a reverse migration should do the logical opposite of a forward migration. forward()
and reverse()
functions can contain anything that the ArangoDB V8 engine understands, but must be fully self-contained. Anything outside these functions is ignored and unavailable when running migrations.
Here's an example migration script for adding new_field
in collection things
:
// write things
function forward(db) {
var db = require("@arangodb").db
db.query(`
FOR thing IN things
UPDATE thing WITH { new_field: "some value" } IN things
`)
}
function reverse(db) {
db.query(`
FOR thing IN things
REPLACE thing WITH UNSET(thing, "new_field") IN things
`)
}
Please make sure you read limitations when running transactions in the ArangoDB documentation. In particular, creation and deletion of databases, collections, and indexes is not allowed in transactions.
Schema migrations
Schema migrations are stuctured in the same way as data migrations, but are run against arangosh
as opposed to the HTTP API. There is no transaction safety when running schema migrations.
Schema migrations are structured the same way as data migrations, but // write
declarations are not required. All operations are allowed.
Here's an example migration script generated from the YAML schema above:
function forward(db) {
db._createDocumentCollection("books")
db._createDocumentCollection("authors")
db._createEdgeCollection("author_of")
}
function reverse(db) {
db._drop("books")
db._drop("authors")
db._drop("author_of")
}
Please be careful when running schema migrations in reverse. As you can see, the reverse()
function above would drop your collections if you were to reverse beyond this point. Currently, you will not be able to do so for an initial migration.
Influenced From
- Django ORM - Python
- Umzug
- Migrado - Python