Coder Social home page Coder Social logo

odonno / surrealdb-migrations Goto Github PK

View Code? Open in Web Editor NEW
177.0 4.0 16.0 496 KB

An awesome SurrealDB migration tool, with a user-friendly CLI and a versatile Rust library that enables seamless integration into any project.

Home Page: https://crates.io/crates/surrealdb-migrations

License: MIT License

Rust 99.94% Shell 0.06%
crates events migrations migrations-generator rust schema surrealdb

surrealdb-migrations's Introduction

Crates.io GitHub Workflow Status GitHub codecov

SurrealDB Migrations

An awesome SurrealDB migration tool, with a user-friendly CLI and a versatile Rust library that enables seamless integration into any project.

Warning This project is not production-ready, use at your own risk.

This project can be used:

  • as a Rust library
cargo add surrealdb-migrations
  • or as a CLI
cargo install surrealdb-migrations

Check surrealdb-migrations GitHub Action in the marketplace

The philosophy

The SurrealDB Migrations project aims to simplify the creation of a SurrealDB database schema and the evolution of the database through migrations. A typical SurrealDB migration project is divided into 3 categories: schema, event and migration.

A schema file represents no more than one SurrealDB table. The list of schemas can be seen as the Query model (in a CQRS pattern). The schemas folder can be seen as a view of the current data model.

An event file represents no more than one SurrealDB event and the underlying table. The list of events can be seen as the Command model (in a CQRS pattern). The events folder can be seen as a view of the different ways to update the data model.

A migration file represents a change in SurrealDB data. It can be a change in the point of time between two schema changes. Examples are: when a column is renamed or dropped, when a table is renamed or dropped, when a new data is required (with default value), etc...

Get started

stateDiagram-v2
    scaffold : Scaffold a project
    changeSchema : Change schema/event
    createMigration: Create migration (data changes)
    apply : Apply to your database

    state fork_state <<fork>>
        [*] --> scaffold
        scaffold --> fork_state
        fork_state --> changeSchema
        fork_state --> createMigration

    state join_state <<join>>
        changeSchema --> join_state
        createMigration --> join_state
        join_state --> apply
        apply --> fork_state

1. Scaffold

You can start a migration project by scaffolding a new project using the following command line:

surrealdb-migrations scaffold template empty

This will create the necessary folders and files in order to perform migrations. The empty template should look like this:

  • /schemas
    • script_migration.surql
  • /events
  • /migrations

There are a number of pre-defined templates so you can play around and get started quickly.

2. Change schema and/or create data change migrations

Once you have created your migration project, you can start writing your own model. Based on the folders you saw earlier, you can create schema files, event files and migration files.

Schemas

You can create strict schema files that represent tables stored in SurrealDB.

surrealdb-migrations create schema post --fields title,content,author,created_at,status

This will create a schemaless table with predefined fields:

DEFINE TABLE post SCHEMALESS;

DEFINE FIELD title ON post;
DEFINE FIELD content ON post;
DEFINE FIELD author ON post;
DEFINE FIELD created_at ON post;
DEFINE FIELD status ON post;

Events

You can also create events in the same way.

surrealdb-migrations create event publish_post --fields post_id,created_at

This will define a table event with predefined fields:

DEFINE TABLE publish_post SCHEMALESS;

DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;

DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == "CREATE" THEN (
    # TODO
);

Migrations

And when updating data, you can create migration files this way:

surrealdb-migrations create AddAdminUser

This will create a new file using the current date & time of the day, like 20230317_153201_AddAdminUser.surql for example. All migrations files should be listed in a temporal order.

3. Apply to your database

Finally, when you are ready, you can apply your schema and migrations to the database using the following command line:

surrealdb-migrations apply

Or directly inside your Rust project using the following code:

use surrealdb_migrations::MigrationRunner;
use surrealdb::engine::any::connect;
use surrealdb::opt::auth::Root;

#[tokio::main]
async fn main() -> Result<()> {
    let db = connect("ws://localhost:8000").await?;

    // Signin as a namespace, database, or root user
    db.signin(Root {
        username: "root",
        password: "root",
    }).await?;

    // Select a specific namespace / database
    db.use_ns("namespace").use_db("database").await?;

    // Apply all migrations
    MigrationRunner::new(&db)
        .up()
        .await
        .expect("Failed to apply migrations");

    Ok(())
}

4. Repeat

Repeat the process from step 2. Change schema and/or create data change migrations.

Predefined templates

To help you get started quickly, there is a list of predefined templates you can use:

Template Description
empty The smallest migration project you can create.
A clean schema with an already defined script_migration table to store the applied migrations.
blog A blog domain model, with users having the ability to publish/unpublish posts and comments.
ecommerce An ecommerce domain model, with customers having the ability to purchase products.

You can scaffold a project using any of these templates using the following command line:

surrealdb-migrations scaffold template <TEMPLATE>

Configuration

You can create a .surrealdb configuration file at the root of your project. This way you won't have to set the same configuration values every time.

[core]
    path = "./tests-files"
    schema = "less"

[db]
    address = "ws://localhost:8000"
    username = "root"
    password = "root"
    ns = "test"
    db = "test"

In the core section, you can define the path to your schema/migration files, if it is not the current folder.

In the db section, you can define the values used to access your SurrealDB database. It can be the url, username, password, the namespace ns or the name of the database db.

Here is the definition of the .surrealdb configuration file:

[core]
    # Optional
    # Type: String
    # Description: Path to the folder that contains your migration project (root folder by default)
    # Default: "."
    path

    # Optional
    # Type: "less" | "full"
    # Description: Define SCHEMALESS or SCHEMAFULL option by default when creating new table/event file
    # Default: "less"
    schema

[db]
    # Optional
    # Type: String
    # Description: Address of the surrealdb instance
    # Default: "ws://localhost:8000"
    address

    # Optional
    # Type: String
    # Description: Username used to authenticate to the surrealdb instance
    # Default: "root"
    username

    # Optional
    # Type: String
    # Description: Password used to authenticate to the surrealdb instance
    # Default: "root"
    password

    # Optional
    # Type: String
    # Description: Namespace to use inside the surrealdb instance
    # Default: "test"
    ns

    # Optional
    # Type: String
    # Description: Name of the database to use inside the surrealdb instance
    # Default: "test"
    db

Backward migrations

By default, migrations are forward-only. However, it can be interesting to revert a migration in order to undo a mistake. You will find backward migrations in two places:

  1. Inside the /migrations/down folder with the same name as your forward migration
  2. Inside the /migrations but with the .down.surql extension next to the forward migration

So, a migration project with backward migrations might look like this:

  • /schemas
    • script_migration.surql
  • /events
  • /migrations
    • 20231605_205201_AddProduct.surql
    • /down
      • 20231605_205201_AddProduct.surql

Or like this:

  • /schemas
    • script_migration.surql
  • /events
  • /migrations
    • 20231605_205201_AddProduct.surql
    • 20231605_205201_AddProduct.down.surql

If you want to create a DOWN migration file when creating the migration file, use this command:

surrealdb-migrations create AddProduct --down

If you need to, you can revert all migrations back to the one you specified.

surrealdb-migrations apply --down 20231605_205201_AddProduct

And if you need to undo all your migrations, use this command:

surrealdb-migrations apply --down 0

Database branching

Database branching is a similar concept to version control system like Git where you manage code repositories with branches.

With database branching, you can create a separate copy or branch of the main database to perform various tasks such as testing new features, implementing changes, or running experiments. This allows developers or teams to work independently on different branches without interfering with the stability and integrity of the original database.

You can make make schemas changes, apply new migrations and/or change data on a separate branch. These changes are isolated from the main database until they are merged back, allowing for better control and organization of database changes.

Development workflow

In a development workflow, you have a primary/main database that contains the latest features on your project. You often work on multiple features or you want to try the work of your colleagues but it messes up your development database, whether you are using migrations or not. Database branching allows you to create a fork of the main database, work on a new feature, apply schema or data changes and then merge your new changes to the main database when your feature is ready.

stateDiagram-v2
    main : Main branch
    createBranch : Create branch "feature-1"
    makeChanges : Make changes on "feature-1"
    merge : Merge "feature-1" on main
    remove : Remove branch "feature-1"

    [*] --> main
    main --> [*]
    main --> createBranch
    createBranch --> makeChanges
    makeChanges --> remove
    makeChanges --> merge
    remove --> [*]
    merge --> [*]

You start by creating a new branch using the following command line:

surrealdb-migrations branch new --address http://localhost:8000

You will then receive a message like this:

You can now use the branch with the following configuration:

ns: branches
db: bright-fold-1617

You can now make your changes on the newly generated database using ns and db properties. When you are done with your changes, you can merge your branch to the origin branch using the following command line:

surrealdb-migrations branch merge bright-fold-1617 --mode all --address http://localhost:8000

There are 3 merge modes, each with its own interest:

Mode Description Status
schema-only A diff of schema will be applied between the branch and the origin branch at the moment of the branch creation.

If possible, the merge will operate schema changes on the origin branch:
* defining new tables, fields, etc...
* removing tables, fields, etc...
Planned
all As an extension to the schema-only mode, a diff of schema and data will be applied between the branch and the origin branch at the moment of the branch creation.

If possible, the merge will operate schema and data changes on the origin branch:
* defining new tables, fields, etc...
* removing tables, fields, etc...
* adding, updating or removing table rows/columns
Planned
overwrite Merging the branch will completely destroy the origin branch and replace it with the new one.
The main branch will have the schema and the data set in the merged branch.
In progress

Production workflow

TBD

Database restrictions

This feature requires 3 namespaces:

  • features
  • branches
  • branches/origin

It is strongly recommended to avoid using one of these namespaces in your SurrealDB instance.

Documentation

# create new branch from current branch with a random name, from default ns/db
surrealdb-migrations branch new
# create new branch from current branch with a name, from default ns/db
surrealdb-migrations branch new <BRANCH_NAME>
# create new branch, from a specific ns/db
surrealdb-migrations branch new --ns <NS> --db <DB>

# review diffs between original branch and the new branch
surrealdb-migrations branch diff <BRANCH_NAME>

# commit and merge branch changes to the original branch
surrealdb-migrations branch merge <BRANCH_NAME>

# remove branch (ie. rollback)
surrealdb-migrations branch remove <BRANCH_NAME>

# list all existing branches
surrealdb-migrations branch list

# display infos of a branch
surrealdb-migrations branch status <BRANCH_NAME>
surrealdb-migrations branch <BRANCH_NAME>

Samples

This project contains sample apps that demontrates how to use the surrealdb-migrations given certain contexts. Here is a list of existing samples:

Name Description Languages/Frameworks
wasm This project shows how to use the surrealdb-migrations crate with embedded migrations files in a WASM context.
The app entry point is powered by SvelteKit and the vite-plugin-rsw plugin.
The SurrealDB data is stored locally in IndexedDb.
SvelteKit/Rust (WASM)

Let's see Paul Allen's contributions

Thanks goes to these wonderful people (emoji key):

Amar Sood
Amar Sood

๐Ÿ’ป
Rom's
Rom's

๐Ÿ’ป ๐Ÿค” ๐Ÿš‡
Pranay Pratyush
Pranay Pratyush

๐Ÿ›
Zafar Ansari
Zafar Ansari

๐Ÿค”
Tim
Tim

๐Ÿค”
Matt Jackson
Matt Jackson

๐Ÿ›
Lucas
Lucas

๐Ÿค”

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Inspired by awesome projects:

surrealdb-migrations's People

Contributors

gibbz00 avatar johansmitsnl avatar liamwh avatar marcocondrache avatar odonno avatar roms1383 avatar tekacs avatar turbohz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

surrealdb-migrations's Issues

Migrate tests to cargo-nextest

Is your feature request related to a problem? Please describe.

N/A

Describe the solution you'd like

Migrate tests to cargo-nextest to improve test performance and make use of interesting features of this tool (identify slow and leaky tests, etc...).

Describe alternatives you've considered

N/A

Additional context

Tests should run fast. This tool is praising itself by saying "Up to 3ร— as fast as cargo test". If true, apply migration to this tool.

cargo install surrealdb-migrations fail stack overflow in geo

I've just tried the cargo install (cargo add worked fine) of v0.9.11 on Rust 1.171.0

Got this compile error.

Regards

Dave

error[E0275]: overflow evaluating the requirement `[closure@/home/dave/.cargo/registry/src/index.crates.io-6f17d22bba15001f/geo-0.24.1/src/algorithm/map_coords.rs:855:69: 855:72]: Fn<(geo_types::Coord<T>,)>`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`geo`)
  = note: required for `&[closure@/home/dave/.cargo/registry/src/index.crates.io-6f17d22bba15001f/geo-0.24.1/src/algorithm/map_coords.rs:855:69: 855:72]` to implement `Fn<(geo_types::Coord<T>,)>`
  = note: 128 redundant requirements hidden
  = note: required for `&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...` to implement `Fn<(geo_types::Coord<T>,)>`
  = note: the full type name has been written to '/tmp/cargo-installBhDx5o/release/deps/geo-1ba9ff62a3464a0b.long-type-12786843144496384107.txt'

For more information about this error, try `rustc --explain E0275`.
error: could not compile `geo` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `surrealdb-migrations v0.9.11`, intermediate artifacts can be found at `/tmp/cargo-installBhDx5o`

Rerun a single old migration

I have a use case that I sometimes need to rerun/reapply a single old migration because I'm modifying the migration during development. Would it be feasible to add a 'reapply' command that runs the corresponding 'down' migration and applies the single old migration?

Failed to apply database migrations: _initial.json file not found in the migrations/definitions directory

Describe the bug
When starting the tauri app. The following error occurs.

To Reproduce
Steps to reproduce the behavior:

When using the surrealdb_migrations package, I'm getting the error: Failed to apply database migrations: _initial.json file not found in the migrations/definitions directory. This is weird, since this file is neither mentioned or generated by the package itself.

My setup is like this:

const DB_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/database/");

#[derive(Debug, Clone)]
pub struct Database {
    conn: Surreal<Db>,
}

impl Database {
    pub async fn init(path: PathBuf) -> Result<Self, surrealdb::Error> {
        let conn = Surreal::new::<File>(path).await?;

        conn.use_ns("default").use_db("default").await?;

        MigrationRunner::new(&conn).load_files(&DB_DIR)
            .up()
            .await
            .expect("Failed to apply database migrations");

        Ok(Database { conn })
    }
}

Is this a known error?

Expected behavior
The migrations run normally

Information
Please complete the following information and remove the unnecessary ones.

  • SurrealDB version: 1.2.2
  • surrealdb-migration version:1.2.2

Create dedicated library

In order to:

  • remove dead code between main.rs and lib.rs
  • remove duplicated code between src and tests

Error in down migration: `Specify some SQL code to execute`

I followed the readme very closely however I run into the issue that my call to down migrate to 0 fails:

surrealdb-migrations apply --down 0   --address ws://localhost:8000 --ns myns --db mydb --username root --password root

with

Error: Specify some SQL code to execute

I have specified valid SQL code in all of the schema, (down)migration. The interesting thing is that down migration works with the blog example. So I tried to add a new migration AddPost, and copied the content of the blog example (20230628_155502_AddPost.surql) to my migration files, as well as the schema.

image

Do you have any idea of what I could be doing wrong, and how to debug this further? Thanks!

Improved error log with failed transactions

When a migration fails with

Error: The query was not executed due to a failed transaction

Caused by:
    The query was not executed due to a failed transaction

I'd like to see a more verbose error message what the reason was for the failed transaction. Would it be possible to display this information?

Bug: `READONLY` keyword

Describe the bug

surrealdb-migrations apply
Error:
   0: Parse error: Failed to parse query at line 19 column 2 expected one of FLEX(IBLE), TYPE, VALUE, ASSERT, DEFAULT, or COMMENT
   0:    |
   0: 19 | READONLY;
   0:    | ^
   0:
   1: Parse error: Failed to parse query at line 19 column 2 expected one of FLEX(IBLE), TYPE, VALUE, ASSERT, DEFAULT, or COMMENT
   1:    |
   1: 19 | READONLY;
   1:    | ^
   1:

To Reproduce
Using Surreal's new READONLY feature

Information

  • SurrealDB version: v1.2.0-beta.1
  • surrealdb-migration version: 1.0.1

Running `cargo install surrealdb-migrations` currently fails

Describe the bug
Running cargo install surrealdb-migrations fails with the following output:

$ cargo install surrealdb-migrations
Updating crates.io index
Installing surrealdb-migrations v0.9.12
Updating crates.io index
Compiling proc-macro2 v1.0.69
...
Compiling surrealdb v1.0.0
Compiling cli-table v0.4.7
Compiling convert_case v0.6.0
Compiling clap v4.4.8
Compiling rust-ini v0.19.0
Compiling diffy v0.3.0
Compiling chrono-human-duration v0.1.1
Compiling sqlparser v0.34.0
Compiling fs_extra v1.3.0
Compiling surrealdb-migrations v0.9.12
error[E0308]: mismatched types
--> /Users/rjara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-migrations-0.9.12/src/surrealdb.rs:66:5
|
66 | / client
67 | | .signin(Root {
68 | | username: &username,
69 | | password: &password,
70 | | })
71 | | .await
| |______________^ expected Result<(), Error>, found Result<Jwt, Error>
|
= note: expected enum Result<(), _>
found enum Result<Jwt, _>

To Reproduce
Either:

  1. cargo install surrealdb-migrations --force

or

  1. clone this repo and navigate to the root directory
  2. git checkout v0.9.12
  3. rm Cargo.lock
  4. cargo clean
  5. cargo build

Please note step 3, which is definitely necessary to get the build to fail.

Expected behavior
cargo install surrealdb-migrations should not fail.

Information

  • SurrealDB version: 1.0
  • surrealdb-migration version: 0.9.12

Additional context
The Cargo.lock file currently checked in under v0.9.12 uses surrealdb version 1.0.0-beta.9+20230402. On a clean install you get version 1.0.0 (without the beta.9+20230402).

Import from existing database (from sql file)

Import/Scaffold a SurrealDB schema from an existing SQL file:

  • BigQuery (untested)
  • ClickHouse (untested)
  • Hive (untested)
  • MS SQL Server = partial support
    • Table definition
    • Column definition
    • Foreign keys (via record types)
    • Simple indexes
    • Unique indexes
    • Assertions
      • NOT NULL
      • Minlength/maxlength
    • Value
      • Default value
    • Extra features
      • Computed columns
      • Geometry types
  • MySQL (untested)
  • PostgreSql (untested)
  • Redshift (untested)
  • SQLite (untested)
  • Snowflake (untested)

Unable to install surrealdb-migrations v0.9.12 on Mac

Describe the bug
I'm unable to install surrealdb-migrtions V0.9.12 on Mac. I'm getting this error:

error: failed to compile surrealdb-migrations v0.9.12, intermediate artifacts can be found at /var/folders/k5/5jb6fd397q533zjk9ql2d5pr0000gn/T/cargo-installMPq8Bd

Caused by:
failed to download replaced source registry crates-io

Caused by:
failed to verify the checksum of surrealdb v1.0.0-beta.9+20230402

To Reproduce
I've just installed cargo version cargo 1.71.1 (7f1d04c00 2023-07-29) using curl https://sh.rustup.rs -sSf | sh
Then I've simply run command cargo install surrealdb-migrations
And I get the error above

Expected behavior
I'd expect surrealdb-migrations to install

Information

  • Mac version [Ventura 13.4.1]
  • Mac chip [M1]
  • SurrealDB version: [1.0.0-beta.9+20230402.5eafebd for linux on aarch64]
  • surrealdb-migration version: [0.9.12]

Thankyou

I was searching for a way for users to do schema evolution of the DSL inside surrealDB and it looks like this can do it.

I am amazed this is not a core part of surrealDB actually because itโ€™s such an important thing to be able to upgrade production / live system

missing field `executed_at`

@Odonno While trying to apply migrations using surrealdb-migrations apply I get the following error:

Error: Failed to convert `[{ id: script_migration:0h0r8c71clh98jciohol, script_name: '20230717_225815_001_Index' }, { executed_at: '2023-07-17T21:56:38.217948925Z', id: script_migration:iwf5blj1nk7d5oj3pv8o, script_name: '20230717_225627_script_migration' }]` to `T`: missing field `executed_at`

Here is a screenshot for my migration folder:

Screenshot 2023-07-17 at 23 15 21

I noticed from the error that script_migration as executed_at field in 20230717_225627_script_migration.surql but
20230717_225815_001_Index.surql does not have executed_at field, hence the error.

Screenshot 2023-07-17 at 23 17 10 Screenshot 2023-07-18 at 05 27 44

Error listing schemas directory

Describe the bug
Error listing schemas directory

To Reproduce

match MigrationRunner::new(&surrealdb).up().await {
        Ok(_) => tracing::info!("Migrations done"),
        Err(err) => panic!("Failed to apply migrations: {err}"),
    };

Expected behavior
Migrate

Information
Please complete the following information and remove the unnecessary ones.

  • SurrealDB version: 1.0.0-beta.9+20230402.5eafebd for linux on x86_64
  • surrealdb-migration version: 0.9.12

cargo install error expected `Result<(), Error>`, found `Result<Jwt, Error>`

Describe the bug
To Reproduce
cargo install surrealdb-migrations returns the following error

error[E0308]: mismatched types
--> /Users/markolazic/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-migrations-0.9.12/src/surrealdb.rs:66:5
|
66 | / client
67 | | .signin(Root {
68 | | username: &username,
69 | | password: &password,
70 | | })
71 | | .await
| |______________^ expected Result<(), Error>, found Result<Jwt, Error>
|
= note: expected enum Result<(), _>
found enum Result<Jwt, _>

For more information about this error, try rustc --explain E0308.
error: could not compile surrealdb-migrations (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile surrealdb-migrations v0.9.12, intermediate artifacts can be found at /var/folders/qq/wdsqkg0n1kd825nr3npkckyh0000gn/T/cargo-installvcFG0T.
To reuse those artifacts with a future compilation, set the environment variable CARGO_TARGET_DIR to that path.

  • SurrealDB version: 1.0.0-beta.9
  • surrealdb-migration version: 0.9.12
  • On MacOS M1

It seem to be compiling surrealdb v1.0.0-beta.11

Unable to install via Cargo

cargo install surrealdb-migrationsย :

   Compiling surrealdb v1.4.2
error: `jwks` depends on a currently unstable feature, `sql2`. You need to enable the `surrealdb_unstable` flag to use it.
   --> /home/thomas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-1.4.2/src/lib.rs:124:1
    |
124 | compile_error!("`jwks` depends on a currently unstable feature, `sql2`. You need to enable the `surrealdb_unstable` flag to use it.");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `sql2` is currently unstable. You need to enable the `surrealdb_unstable` flag to use it.
   --> /home/thomas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-1.4.2/src/lib.rs:127:1
    |
127 | / compile_error!(
128 | |     "`sql2` is currently unstable. You need to enable the `surrealdb_unstable` flag to use it."
129 | | );
    | |_^

error: could not compile `surrealdb` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `surrealdb-migrations v1.4.1`, intermediate artifacts can be found at `/tmp/cargo-installT1L2t6`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

rustc 1.77.1 (7cf61ebde 2024-03-27)
cargo 1.77.1 (e52e36006 2024-03-26)

Thanks for your help.

Unable to install surrealdb-migrations error[E0658]: use of unstable library feature 'stdsimd'

Describe the bug
When I try to install surrealdb-migrations with cargo install surrealdb-migrations I get this error:
error[E0658]: use of unstable library feature 'stdsimd'

error[E0658]: use of unstable library feature 'stdsimd'
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ahash-0.8.7/src/operations.rs:124:24
|
124 | let res = unsafe { vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(0u128))) };
| ^^^^^^^^^^
|
= note: see issue #48556 rust-lang/rust#48556 for more information

error[E0658]: use of unstable library feature 'stdsimd'
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ahash-0.8.7/src/operations.rs:124:35
|
124 | let res = unsafe { vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(0u128))) };
| ^^^^^^^^^
|
= note: see issue #48556 rust-lang/rust#48556 for more information

Compiling quote v1.0.35
error[E0658]: use of unstable library feature 'stdsimd'
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ahash-0.8.7/src/operations.rs:154:24
|
154 | let res = unsafe { vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(0u128))) };
| ^^^^^^^^^^^
|
= note: see issue #48556 rust-lang/rust#48556 for more information

error[E0658]: use of unstable library feature 'stdsimd'
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ahash-0.8.7/src/operations.rs:154:36
|
154 | let res = unsafe { vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(0u128))) };
| ^^^^^^^^^
|
= note: see issue #48556 rust-lang/rust#48556 for more information

For more information about this error, try rustc --explain E0658.
error: could not compile ahash (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile surrealdb-migrations v1.0.1, intermediate artifacts can be found at /var/folders/k5/5jb6fd397q533zjk9ql2d5pr0000gn/T/cargo-installa1UZKR

Information

  • SurrealDB version: 1.1.1 for macos on aarch64
  • surrealdb-migration version: 1.0.1

Provide a way to load migrations from a dir at runtime (not embedded)

Is your feature request related to a problem? Please describe.

I only want to run the migrations automatically during integration testing. Currently I have a variable DB_MIGRATIONS_DIR defined which points to my migrations directory which is called surrealdb. I need to set that variable locally, in in the GitHub pipelines.

Describe the solution you'd like
I would like to get rid of that variable and use env::current_dir().unwrap().parent().unwrap().join("surrealdb") to get the path to my migrations directory.

Strict mode apparently unsupported

Describe the bug

The tool does not work when running a SurrealDB instance with SURREAL_STRICT=true.

To Reproduce

  1. Start SurrealDB with SURREAL_STRICT=true.
  2. surrealdb-migrations scaffold template empty
  3. surrealdb-migrations apply

Initially, youโ€™ll get:

Error: There was a problem with the database: The namespace 'test' does not exist

If you create the namespace and database already defined in the config file, then you get:

Error: There was a problem with the database: The table 'script_migration' does not exist

Expected behavior

Successful creation of the script_migration table.

Perhaps, even, the namespace and database specified in the configuration file (debatable).

Information

  • SurrealDB version: Docker surrealdb/surrealdb:1.0.0
  • surrealdb-migration version: 1.0.0-preview.1

"`sql2` is currently unstable. You need to enable the `surrealdb_unstable` flag to use it."

Describe the bug
When using the library with the current version of surrealdb it throws the error described above.

To Reproduce
Steps to reproduce the behavior:

  1. Add the following to Cargo.toml
surrealdb = { version = "1.2.0", features = ["kv-rocksdb"] }
surrealdb-migrations = "1.2.2"
  1. Start project

Expected behavior
To run through without error

Information
I guess the solution to the problem is described in the error itself, but when I add surrealdb_unstable as a feature of surrealdb-migrations it can't find it.

  • SurrealDB version: 1.2.0
  • surrealdb-migration version: 1.2.2

Question: Applying migrations fails during CI - file not found.

Question:

Is the .surrealdb configuration file required?

Issue:

As I was writing this, I realized I also had this issue when trying to invoke the CLI from an initialization script. For some reason, whether I have a configuration file specified or not, the test panics with the following during CI (Github actions):

CI Panic: 'Failed to run migrations.: Path does not directory'

Note, this works when invoking cargo test but breaks when Github actions fires so I'm sure it's some sort of relative path thing, but I'm not entirely sure.

File: tests/health_check.rs

pub async fn configure_database(config: SurrealdbConfiguration) -> color_eyre::Result<()> {
    SurrealdbMigrations::new(config)
        .up()
        .await
        .expect("Failed to run migrations.");

    Ok(())
}

Repo:

  • zero2axum - working through Zero to Production w/Axum & SurrealDB (or at least trying to)

Feature: use local config files

Is your feature request related to a problem? Please describe.
In scenarios where there are monorepos, which might have multiple schemas, it should be possible to have multiple schemas by having config files at a folder level from where the CLI is in the CWD.

Beta and nightly version support

I would like to be able to use surrealdb-migrations with the beta / nightly images.

It would be amazing if CI/CD could be setup to release a beta version and a nightly version of the surrealdb-migrations crate, like they do with surrealdb crate itself.

Feature: Publish to Homebrew

Is your feature request related to a problem? Please describe.
To help with local development it'll be easy if the CLI is available through Homebrew.

Describe alternatives you've considered
Manual installation for the Mac.

CLI doesn't compile on arm with nightly build >1.71.0 (7908a1d65 2023-04-17)

The error produced is:

error[E0275]: overflow evaluating the requirement `[closure@/Users/lro/.cargo/registry/src/index.crates.io-6f17d22bba15001f/geo-0.24.1/src/algorithm/map_coords.rs:855:69: 855:72]: Fn<(geo_types::Coord<T>,)>`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`geo`)
  = note: required for `&[closure@map_coords.rs:855:69]` to implement `Fn<(geo_types::Coord<T>,)>`
  = note: the full type name has been written to '/var/folders/vz/mcg3p00n099bxp3rdvjj6f5c0000gn/T/cargo-installUfxvvY/release/deps/geo-b2aff91d3d37fe24.long-type-17612579219348647092.txt'
  = note: 128 redundant requirements hidden
  = note: required for `&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...` to implement `Fn<(geo_types::Coord<T>,)>`
  = note: the full type name has been written to '/var/folders/vz/mcg3p00n099bxp3rdvjj6f5c0000gn/T/cargo-installUfxvvY/release/deps/geo-b2aff91d3d37fe24.long-type-4872500827442011049.txt'

For more information about this error, try `rustc --explain E0275`.
error: could not compile `geo` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `surrealdb-migrations v0.9.5`, intermediate artifacts can be found at `/var/folders/vz/mcg3p00n099bxp3rdvjj6f5c0000gn/T/cargo-installUfxvvY`

This is the related issue in the geo library georust/geo#1010.
It is fixed in geo 0.25.0.
For now I just use an earlier nightly version for it to work.

Large migration does not terminate

I am trying to run a "large" migration (about 130k update statements) and the output displays "Executing migration..." for >10min but I don't see any updates/changes in the SurrealDB log. Splitting the migration into two migrations with 60k statements runs in <1min. What could be the issue here?

Feature: Seeding

Is your feature request related to a problem? Please describe.

Seeding is a common feature provided by ORMs and migration tools like Eloquent and Prisma

Describe the solution you'd like

A seed file that is executed when the database is first setup.

Describe alternatives you've considered

Manually running SURQL on setup, but this can be tedious for large operations.

Error: Path "migrations/definitions" is not a file!

using surrealdb-migrations 0.9.9
trying to apply migrations created from a template made with 0.9.6, I get the error in the title.
I'm running surrealdb-migrations apply with 3 folders, events, schemas and migrations
my migrations folder contains the following

ls migrations/
โ”‚ 0 โ”‚ migrations/20230517_113302_InitialSetup.surql โ”‚ 4.2 KB โ”‚
โ”‚ 1 โ”‚ migrations/down                               โ”‚    3 B โ”‚
โ”‚ 2 โ”‚ migrations/definitions                        โ”‚    2 B โ”‚

do I have to move my migration inside the definitions folder ?

I didn't have a definitions folder, but when I run the apply, it creates it for me.

Running large migration file fails

Describe the bug

Running a migration file of size 67MB fails with error below. I also see a debug error from surreal binary: WebSocket error: Error { inner: Io(Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }) }. I wonder if this has to do with surrealdb/surrealdb#2965

To Reproduce

I can share the file if necessary.

Expected behavior

Run the migration.

Information

  • SurrealDB version: 1.0.0-beta.9+20230402.5eafebd for linux on x86_64
  • surrealdb-migration version: 1.0.0

Additional context

Could it be related to WEBSOCKET_MAX_FRAME_SIZE being only 16MB see here.

Error: 
   0: There was an error processing a remote WS request: IO error: Connection reset by peer (os error 104)
   1: There was an error processing a remote WS request: IO error: Connection reset by peer (os error 104)

Location:
   src/surrealdb.rs:156

  โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” BACKTRACE โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
   1: color_eyre::config::EyreHook::into_eyre_hook::{{closure}}::hd7da39aef3605027
      at <unknown source file>:<unknown line>
   2: eyre::capture_handler::hb1303c31a6ee2ec0
      at <unknown source file>:<unknown line>
   3: eyre::error::<impl eyre::Report>::from_std::hced59842f21ef8b9
      at <unknown source file>:<unknown line>
   4: surrealdb_migrations::surrealdb::apply_in_transaction::{{closure}}::hca01a80ce835ab29
      at <unknown source file>:<unknown line>
   5: surrealdb_migrations::apply::main::{{closure}}::h8128f5e36f828d15
      at <unknown source file>:<unknown line>
   6: surrealdb_migrations::main::{{closure}}::hc0a43bb13bf60e85
      at <unknown source file>:<unknown line>
   7: tokio::runtime::park::CachedParkThread::block_on::he6fb9cbd2e19c0d2
      at <unknown source file>:<unknown line>
   8: tokio::runtime::context::runtime::enter_runtime::h23806c7a69b68cf1
      at <unknown source file>:<unknown line>
   9: surrealdb_migrations::main::h6dc4d609382dc6ac
      at <unknown source file>:<unknown line>
  10: std::sys_common::backtrace::__rust_begin_short_backtrace::h3b5ad835699c4947
      at <unknown source file>:<unknown line>
  11: std::rt::lang_start::{{closure}}::had3220220a969bf1
      at <unknown source file>:<unknown line>
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h82652f9ce79fee66
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:284
  13: std::panicking::try::do_call::he4b5337a350acea1
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:504
  14: std::panicking::try::hd48750cb63f7f01f
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:468
  15: std::panic::catch_unwind::h81e9ecf5c019a4bd
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panic.rs:142
  16: std::rt::lang_start_internal::{{closure}}::hef99b32d530f302f
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/rt.rs:148
  17: std::panicking::try::do_call::h223c3327abf6d3d9
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:504
  18: std::panicking::try::ha6263cc242c2d045
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:468
  19: std::panic::catch_unwind::h38c8a27284d90e98
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panic.rs:142
  20: std::rt::lang_start_internal::h2d2b3c117ba7283e
      at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/rt.rs:148
  21: main<unknown>
      at <unknown source file>:<unknown line>

Support Surreal<Client>

I wanted to try out the library but I use the Surreal Client which isn't supported as it seems.
I just create a client like this:

let db = Surreal::new::<Ws>("127.0.0.1:8001")
        .await
        .expect("Failed to connect to server");

But the MigrationRunner expects a &Surreal<surrealdb::engine::any::Any>

This is the error I get:

mismatched types
expected reference `&Surreal<surrealdb::engine::any::Any>`
   found reference `&Surreal<Client>`

(integration) tests are flaky

While implementing #56 I noticed that tests will pass sometimes, and then they will not.

When I knew a test should fail, but was passing, I could reliably fix (break again?) the test by restarting the surrealdb instances that are used in the integration tests.

This is probably due to reusing the database, which makes the tests not pure (previous state of the database can influence them).

Ideally each integration test should run in a fresh, uninitialized test database.

From my experience with other languages, they often have hooks to run stuff before/after a test suite or individual tests. I assume something similar can be done in Rust.

Cannot create JWKS token

Describe the bug
It's not possible to apply a migration that creates a JWKS token with surrealdb migrations.

To Reproduce
Create a migration with the following example from the documentation:

https://surrealdb.com/docs/surrealdb/surrealql/statements/define/token#json-web-key-set-jwks-since-120

DEFINE TOKEN token_name
  -- Use this token provider for database authorization
  ON DATABASE
  -- Specify the JWKS specification used to verify the token
  TYPE JWKS 
  -- Specify the URL where the JWKS object can be found
  VALUE "https://example.com/.well-known/jwks.json"
;

This returns an error similar to this:

surrealdb-migrations apply
Error: 
   0: Parse error: Failed to parse query at line 8 column 8 expected query to end
   0:   |
   0: 8 | DEFINE TOKEN ory ON SCOPE user TYPE JWKS VALUE "http://oathkeeper:4456/.well-...
   0:   |        ^ perhaps missing a semicolon on the previous statement?
   0: 
   1: Parse error: Failed to parse query at line 8 column 8 expected query to end
   1:   |
   1: 8 | DEFINE TOKEN ory ON SCOPE user TYPE JWKS VALUE "http://oathkeeper:4456/.well-...
   1:   |        ^ perhaps missing a semicolon on the previous statement?
   1: 

Location:
   /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-migrations-1.4.0/src/surrealdb.rs:157

  โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” BACKTRACE โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
                                โ‹ฎ 3 frames hidden โ‹ฎ                               
   4: surrealdb_migrations::surrealdb::apply_in_transaction::{{closure}}::h6d1e25f40dcf785d
      at <unknown source file>:<unknown line>
   5: surrealdb_migrations::apply::main::{{closure}}::h146ba33a0e095570
      at <unknown source file>:<unknown line>
   6: surrealdb_migrations::sub_main::{{closure}}::heb13da4601b5befe
      at <unknown source file>:<unknown line>
   7: tokio::runtime::park::CachedParkThread::block_on::h2d0b779a8f0f5b12
      at <unknown source file>:<unknown line>
   8: surrealdb_migrations::main::h1ba1c626e949b292
      at <unknown source file>:<unknown line>
   9: std::sys_common::backtrace::__rust_begin_short_backtrace::h3760d9aa58d3944c
      at <unknown source file>:<unknown line>
  10: std::rt::lang_start::{{closure}}::hdf356da95c0fe837
      at <unknown source file>:<unknown line>
  11: std::rt::lang_start_internal::h0ddfe42b2029814a
      at <unknown source file>:<unknown line>
  12: main<unknown>
      at <unknown source file>:<unknown line>
  13: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  14: _start<unknown>
      at <unknown source file>:<unknown line>


Expected behavior
The migration should be applied.

Information
Please complete the following information and remove the unnecessary ones.

  • SurrealDB version: 1.4.2 for linux on x86_64
  • surrealdb-migration: 1.4.0

Additional context
Same issue existed in Surrealist: surrealdb/surrealist#244

Was fixed with enabling the jwks feature for Surreraldb: surrealdb/surrealql.wasm@15c6ead

Running `cargo install surrealdb-migrations' fails

Tried to replace the cli 1.2 with the release of yesterday 1.3.0:

cargo install surrealdb-migrations

got this:

Compiling surrealdb v1.3.1
error: `sql2` is currently unstable. You need to enable the `surrealdb_unstable` flag to use it.
   --> /Users/aroba/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-1.3.1/src/lib.rs:117:1
    |
117 | / compile_error!(
118 | |     "`sql2` is currently unstable. You need to enable the `surrealdb_unstable` flag to use it."
119 | | );
    | |_^

error: could not compile `surrealdb` (lib) due to 1 previous error
error: failed to compile `surrealdb-migrations v1.3.0`, intermediate artifacts can be found at `/var/folders/4s/x3c9vc_12293cn0v02_4bjj80000gn/T/cargo-install0ELWRR`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

empty template isn't there

> RUST_BACKTRACE=full surrealdb-migrations scaffold empty
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: NotFound, message: "Path \"templates/empty\" does not exist or you don't have access!" }', /home/pranay/.cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-migrations-0.9.0/src/scaffold.rs:30:6
stack backtrace:
   0:     0x556a748eecfd - std::backtrace_rs::backtrace::libunwind::trace::h3e12365f7635da3e
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x556a748eecfd - std::backtrace_rs::backtrace::trace_unsynchronized::h7a6be5b9ff250f8e
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x556a748eecfd - std::sys_common::backtrace::_print_fmt::hf818e9f06250646a
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x556a748eecfd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5cd160069c9f3e1b
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x556a747a791f - core::fmt::write::hfa5b61a86171a98e
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/core/src/fmt/mod.rs:1254:17
   5:     0x556a748eb5d5 - std::io::Write::write_fmt::h6c6cd697a3cffe86
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/io/mod.rs:1684:15
   6:     0x556a748eead5 - std::sys_common::backtrace::_print::hf6d49b9c8ff41a80
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x556a748eead5 - std::sys_common::backtrace::print::h3289230cc0e812b8
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x556a748f017e - std::panicking::default_hook::{{closure}}::h15e53b47bd0b6eb4
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:271:22
   9:     0x556a748eff5e - std::panicking::default_hook::ha12d0737cacdd914
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:290:9
  10:     0x556a748f06bb - std::panicking::rust_panic_with_hook::h922001bd476c4440
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:692:13
  11:     0x556a748f05c6 - std::panicking::begin_panic_handler::{{closure}}::h7b8ff317b1305672
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:583:13
  12:     0x556a748ef206 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b041c8b45cfaa82
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x556a748f0362 - rust_begin_unwind
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:579:5
  14:     0x556a747a54f3 - core::panicking::panic_fmt::h1cfb4f6e7e152c39
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/core/src/panicking.rs:64:14
  15:     0x556a747a59c3 - core::result::unwrap_failed::h4ce6a6c5b54d5f95
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/core/src/result.rs:1750:5
  16:     0x556a74b1f5be - surrealdb_migrations::scaffold::main::ha5f6c259dffef8ec
  17:     0x556a74b4da1d - tokio::runtime::park::CachedParkThread::block_on::hc3670c5049e09af6
  18:     0x556a74b4e074 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h12d496ea925d5125
  19:     0x556a74b7afd5 - tokio::runtime::runtime::Runtime::block_on::h6d43a15609401cc9
  20:     0x556a74b636e3 - surrealdb_migrations::main::hce9b347516bcd0c5
  21:     0x556a74b5c733 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6267f9bbb30c5c48
  22:     0x556a74b2e5e9 - std::rt::lang_start::{{closure}}::h1e54fb892a1b0ba3
  23:     0x556a748e63b5 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h9243ec71de803cf7
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/core/src/ops/function.rs:287:13
  24:     0x556a748e63b5 - std::panicking::try::do_call::hd0d1c25df12fa799
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:487:40
  25:     0x556a748e63b5 - std::panicking::try::h2f30a6ec993c55d8
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:451:19
  26:     0x556a748e63b5 - std::panic::catch_unwind::h486078a7c111047a
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panic.rs:140:14
  27:     0x556a748e63b5 - std::rt::lang_start_internal::{{closure}}::h6316820d1737fa0f
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/rt.rs:148:48
  28:     0x556a748e63b5 - std::panicking::try::do_call::h4c2c40d9f15bd6ed
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:487:40
  29:     0x556a748e63b5 - std::panicking::try::h565723515e5171b1
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panicking.rs:451:19
  30:     0x556a748e63b5 - std::panic::catch_unwind::hfca36f898cde3467
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/panic.rs:140:14
  31:     0x556a748e63b5 - std::rt::lang_start_internal::h91330cc7920f9b44
                               at /rustc/4a04d086cac54a41517d5657b59d5fe2caca2d71/library/std/src/rt.rs:148:20
  32:     0x556a74b637b5 - main
  33:     0x7f3a1d7fb790 - <unknown>
  34:     0x7f3a1d7fb84a - __libc_start_main
  35:     0x556a7472a9e5 - _start
  36:                0x0 - <unknown>

First of all surrealdb-migrations scaffold --template empty doesn't work even though it's in the docs. surrealdb-migrations scaffold empty seems to be a valid command but there is no such template apparently.
The panic goes away after I do mkdir -p templates/empty but still everything created is empty

find alternative to 'names' crate

The 'names' crate presently relies on an outdated version of the clap crate internally, which, in turn, still utilizes attyโ€”an unmaintained component with a known vulnerability.

Crate:     atty
Version:   0.2.14
Warning:   unsound
Title:     Potential unaligned read
Date:      2021-07-04
ID:        RUSTSEC-2021-0145
URL:       https://rustsec.org/advisories/RUSTSEC-2021-0145
Dependency tree:
atty 0.2.14
โ””โ”€โ”€ clap 3.2.25
    โ””โ”€โ”€ names 0.14.0
        โ””โ”€โ”€ surrealdb-migrations 1.2.2
            โ”œโ”€โ”€ net 0.1.0
            โ”‚   โ””โ”€โ”€ cli 0.1.0
            โ”‚       โ””โ”€โ”€ sync 0.1.0
            โ””โ”€โ”€ dbm 0.1.0
                โ”œโ”€โ”€ vnd 0.1.0
                โ”‚   โ”œโ”€โ”€ sync 0.1.0
                โ”‚   โ””โ”€โ”€ cli 0.1.0
                โ”œโ”€โ”€ sync 0.1.0
                โ”œโ”€โ”€ rpc 0.1.0
                โ”‚   โ””โ”€โ”€ net 0.1.0
                โ”œโ”€โ”€ cls 0.1.0
                โ”‚   โ”œโ”€โ”€ vnd 0.1.0
                โ”‚   โ”œโ”€โ”€ sync 0.1.0
                โ”‚   โ””โ”€โ”€ rpc 0.1.0
                โ””โ”€โ”€ cli 0.1.0

Parallel integration tests

Integration tests are currently run in serial (one after each other) due to the testing architecture. Improve the testing architecture (and performance?) by allowing integration tests to be run in parallel:

  • Pass the path folder to the cli instead of using the same for every test from .surrealdb configuration file
  • Use a temp dir for each test from assert_fs
  • Run a singular SurrealDB instance for the entire test architecture
    • Using the following GitHub Action? use-surrealdb-in-github-actions
    • Run on port 8000 for user root
    • Run on port 8001 for user test
    • Clean db after/before each test

Support embedded database

Hi there and thanks for this lib it's super convenient to be able to run everything nicely in migrations.
Yesterday I gave a try at opening a PR to add support for embedded database (file/rocksdb/inflxdb) and came up with some result but I'm kinda stuck since the numerous tests are based on surreal cli which is not runnning in typical embedded context.
If you feel like it, maybe you can provide some guidance in implementing appropriate tests ?

Split test library

Is your feature request related to a problem? Please describe.

Related to #58, testing can be tedious and there is some critical paths about tests:

  • tests should run fast (less than 10s), so they should run in parallel
  • tests on "branches" feature cannot be run in parallel because they use the same namespace/database in a SurrealDB instance

Describe the solution you'd like

If possible, split test library into 2 or 3:

  • one for "standard" tests
  • one for "e2e" tests (longer test, with waiting time)
  • one for each limited scope tests, so one for "branches" tests

Describe alternatives you've considered

Use flags with cargo-nextest. Need first to migrate to this tool. #59

Additional context

N/A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.