|
1 | 1 | # KustoSchemaTools |
2 | | -This repository contains C# code to synchronize database schemas from Azure Data Explorer (Kusto) to yaml files and back. |
| 2 | + |
| 3 | +This C# project provides functionality to work with schemas in Azure Data Explorer (Kusto). You can load a schema from yaml files or a database to the interal data structure. This can be used for creating diffs of two databases as scripts or markdown, and also to write it back to files or update schemas in a database. |
| 4 | + |
| 5 | +A second project "[KustoSchemaToolsAction](https://github.com/github/KustoSchemaToolsAction)" wraps that into CLI tool inside a docker container for usage in GitHub Actions. |
| 6 | + |
| 7 | +## Getting started |
| 8 | + |
| 9 | +The `database` object holds all schema related information for a Kusto database. It can be loaded from, or written to a cluster using the `KustoDatabaseHandler` which can be created by the `KustoDatabaseHandlerFactory`.There are several steps involved for loading a all relevant information from a kusto database into the `database` object. These are covered by different plugins, which can be configured for the `KustoDatabaseHandlerFactory`. |
| 10 | + |
| 11 | +```csharp |
| 12 | +var dbFactory = new KustoDatabaseHandlerFactory(sp.GetService<ILogger<KustoDatabaseHandler>>()) |
| 13 | + .WithPlugin<KustoDatabasePrincipalLoader>() |
| 14 | + .WithPlugin<KustoDatabaseRetentionAndCacheLoader>() |
| 15 | + .WithPlugin<KustoTableBulkLoader>() |
| 16 | + .WithPlugin<KustoFunctionBulkLoader>() |
| 17 | + .WithPlugin<KustoMaterializedViewBulkLoader>() |
| 18 | + .WithPlugin<DatabaseCleanup>() |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | + For syncrhonizing it to files, the `YamlDatabaseHandler` and the `YamlDatabaseHandlerFactory` are the right tools. To prevent super large files, there are plugins that handle reading and writing functions, tables and materialized views to separate files and folders. They can be configured for the `YamlDatabaseHandlerFactory`. |
| 23 | + |
| 24 | +```csharp |
| 25 | +var yamlFactory = new YamlDatabaseHandlerFactory() |
| 26 | + .WithPlugin(new TablePlugin()) |
| 27 | + .WithPlugin(new FunctionPlugin()) |
| 28 | + .WithPlugin(new MaterializedViewsPlugin()) |
| 29 | + .WithPlugin<DatabaseCleanup>(); |
| 30 | +``` |
| 31 | + |
| 32 | +Additional features can be added with custom plugins. A sample for `table groups`, where the some parts of the schema are defined once, but is applied for several tables can be found in [here](https://github.com/github/KustoSchemaToolsAction/blob/main/KustoSchemaCLI/Plugins/TableGroupPlugin.cs). |
| 33 | + |
| 34 | +The `KustoSchemaHandler` is the central place for synching schemas between yaml and a database. It offers functions for generating changes formatted in markdown, writing a database to yaml files and applying changes from yaml files to a database. |
| 35 | + |
| 36 | +## Supported Features |
| 37 | + |
| 38 | +Currently following features are supported: |
| 39 | + |
| 40 | +* Database |
| 41 | + * Permissions |
| 42 | + * Default Retention |
| 43 | + * Default Hot Cache |
| 44 | +* Tables |
| 45 | + * Columns |
| 46 | + * Retention |
| 47 | + * HotCache |
| 48 | + * Update Policies |
| 49 | + * Docstring |
| 50 | + * Folder |
| 51 | +* Functions |
| 52 | + * Body |
| 53 | + * Docstring |
| 54 | + * Folder |
| 55 | +* Materialized Views |
| 56 | + * Query |
| 57 | + * Retention |
| 58 | + * HotCache |
| 59 | + * Docstring |
| 60 | + * Folder |
| 61 | + |
| 62 | +The `DatabaseCleanup` will remove redundant retention and hotcache definitions. It will also pretty print KQL queries in functions, update policies and materialized views. |
0 commit comments