Skip to content

Commit

Permalink
doc: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Jan 31, 2024
1 parent f5f97b8 commit 473a6e9
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# surrealdb_migrations
# surrealdb_migrations_engine

Super simple yet power migration engine for surreal db. All you need to get it working is the following
```rust
#[derive(rust_embed::RustEmbed)]
#[folder = "migrations"]
struct MigrationFiles;

#[derive(rust_embed::RustEmbed)]
#[folder = "schema"]
struct SchemaFiles;

async fn main() {
// create surealdb `client`

SurrealdbMigrationEngine::run::<MigrationFiles,SchemaFiles>(&client).await?;

// the rest of your code
}
```
## How It Works
`surrealdb_migration_engine` works on two concepts `migrations` and `schema`. Migrations are queries (changes) to an apply to an existing schema. Schemas are queries that set up the db structure. Schemas and migrations reside in their own directory with each file being numbered in order e.g. `0001_add_age_to_user_table.surql`. Each of these directories is compiled with your binary with the help of the `rust_embed` crate. This means that the appropriate migrations or schema creation will happen at runtime. All migrations and schema changes are done in a single transaction, so if one fails, they all fail.

`surrealdb_migration_engine` creates a `migrations` table inside your database to track which migrations have r n. The logic flow works like this.
- If the migrations table does not exist, run only the `schema` files and enter all current `migration` files into the migration table.
- If the migrations table does exist, run any `migration` files that are not in the `migration` table

Very simple but extremely flexible!

## Uses
- Include `surrealdb_migration_engine` in your application so whenever you run your application, the schema is always up to date.
- Include `surrealdb_migration_engine` in a barebones executable that runs the necessary migrations or schema creation before an application starts.

0 comments on commit 473a6e9

Please sign in to comment.