https://github.com/youssef-ben/cassandra.fluent.migrator
Cassandra Fluent Migrator is a library that offers a set of fluent code and extensions to facilitate the creation and management of the Cassandra migrations using code instead of CQL string commands.
https://github.com/youssef-ben/cassandra.fluent.migrator
cassandra cassandra-fluent-migrator cql csharp fluent fluent-migration fluent-migrator migration migrator netcore netcore3
Last synced: 3 months ago
JSON representation
Cassandra Fluent Migrator is a library that offers a set of fluent code and extensions to facilitate the creation and management of the Cassandra migrations using code instead of CQL string commands.
- Host: GitHub
- URL: https://github.com/youssef-ben/cassandra.fluent.migrator
- Owner: Youssef-ben
- License: gpl-3.0
- Created: 2020-05-28T01:44:44.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T03:13:41.000Z (over 2 years ago)
- Last Synced: 2025-09-20T23:25:07.343Z (9 months ago)
- Topics: cassandra, cassandra-fluent-migrator, cql, csharp, fluent, fluent-migration, fluent-migrator, migration, migrator, netcore, netcore3
- Language: C#
- Homepage:
- Size: 270 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Cassandra Fluent Migrator

Cassandra Fluent Migrator is a library that offers a set of fluent code and extensions to facilitate the creation and management of the migrations using code instead of CQL commands.
## Stack
* [.NET Standard 2.1](https://docs.microsoft.com/en-us/dotnet/standard/net-standard?WT.mc_id=dotnet-35129-website&tabs=net-standard-2-1)
* [Cassandra CSharp driver - v3.17](https://docs.datastax.com/en/developer/csharp-driver/3.16/): A modern, feature-rich and highly tunable C# client library for Apache Cassandra using Cassandra’s binary protocol and Cassandra Query Language v3.
### Installation
* [Get it from NuGet](https://www.nuget.org/packages/Cassandra.Fluent.Migrator/)
```cmd
PM> Install-Package Cassandra.Fluent.Migrator
```
### Future Improvements
* [ ] Add support for more complex types.
* [ ] Add support for the `Materialized views`.
### Documentations
* [Wiki page:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki) Full documentation for the library.
* [Cassandra Migrator:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki/Cassandra-Migrator) The core class of the library.
* [Cassandra Fluent Migrator:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki/Cassandra-Fluent-Migrator) The migration helper class.
* [Migrator interface:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki/Migrator-Interface) The base properties and method that the migrations should implement.
* [Example:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki/Example) An example on how to use the library.
* [Supported Types:](https://github.com/Youssef-ben/Cassandra.Fluent.Migrator/wiki/Supported-Types) List of supported types.
### Basic Usage
* **Migration class**
In your project create a migration class that implements the `IMigrator` Interface as follow:
```C#
public class InitialMigration : IMigrator
{
private readonly ICassandraFluentMigrator cfm;
private readonly ILogger logger;
public InitialMigration(ILogger logger, ICassandraFluentMigrator cfm)
{
this.cfm = cfm;
this.logger = logger;
}
public string Name => this.GetType().Name;
public Version Version => new Version(1, 0, 0);
public string Description => "First migration to initialize the Schema";
public async Task ApplyMigrationAsync()
{
this.logger.LogDebug($"Creating the Address User-Defined type...");
await this.cfm.CreateUserDefinedTypeAsync
();
// Should not be here in real world application.
// Used only for example purposes.
this.cfm
.GetCassandraSession()
.UserDefinedTypes.Define(
UdtMap.For
()
.Map(a => a.Number, "Number".ToLower())
.Map(a => a.Street, "Street".ToLower())
.Map(a => a.City, "City".ToLower())
.Map(a => a.Country, "Country".ToLower())
.Map(a => a.Province, "Province".ToLower())
.Map(a => a.PostalCode, "PostalCode".ToLower()));
this.logger.LogDebug($"Creating the User table...");
await this.cfm.GetTable().CreateIfNotExistsAsync();
}
}
```
* **Startup class**
```C#
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
// Custom method that you can create to initialize the Cassandra {ISession}.
services.AddCassandraSession(this.Configuration);
// Register the migrations
services.AddTransient();
// Required by the library to register the needed classes.
services.AddCassandraFluentMigratorServices();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
// Start the migration process.
app.UseCassandraMigration();
...
}
```