Skip to content

kullbom/dbflow

Repository files navigation

DbFlow

DbFlow is a tool with the ambition to help in all stages of developing, testing and deploying databases.

The current version of DbFlow can be used for

  • generate complete scripts for a database schema that can be used for (as an example) improved version control
  • clone the schema of an existing database to another (resolving dependencies for correct order)
  • create a temporary local database that can be used for unit testing or similar
  • Experimental:* Copy data from one database to another (resolving and copying dependant data as well)

NuGet: https://www.nuget.org/packages/DbFlow/

Repo: https://github.com/kullbom/dbflow

DbFlow supports

  • Microsoft Sql Server

Known bugs/limitation

  • Does not consider ANSI PADDING of individual columns
  • XML indexes is not yet fully supported

Planned features:

  • Improved support for copying data
    • Ignore/transform specific data
  • Replace the need for DbUp
  • Generate documentation
  • Support for PostgreSql

Examples

To clone a database (F#):

open Microsoft.Data.SqlClient
open DbFlow
open DbFlow.SqlServer

let options = Options.Default

let logger _message = ()

let srcConnectionStr = ...
let dstConnectionStr = ...

let dbSchema = 
    use connection = new SqlConnection(srcConnectionStr)
    connection.Open()
    Execute.readSchema logger options connection

use connection = new SqlConnection(dstConnectionStr)
connection.Open()
Execute.clone logger options dbSchema connection 

To generate scripts from a database (F#):

open Microsoft.Data.SqlClient
open DbFlow
open DbFlow.SqlServer

let options = Options.Default

let logger _message = ()

let srcConnectionStr = ...
let dstDirectory = ...

let dbSchema = 
    use connection = new SqlConnection(srcConnectionStr)
    connection.Open()
    Execute.readSchema logger options connection

Execute.generateScriptFiles options dbSchema dstDirectory   

To clone a database (C#):

var logger = LoggerModule.fromFunc(s => { });
            
using var sourceConnection = new Microsoft.Data.SqlClient.SqlConnection(sourceConnectionString);
sourceConnection.Open();
var schema = Execute.readSchema(logger, ReadOptions.Default, sourceConnection);

var cloneDb = Execute.cloneToLocal(logger, LocalDbOptions.Default, ScriptOptions.Default, schema);

To generate scripts from a database (C#):

var logger = LoggerModule.fromFunc(s => { });
            
using var sourceConnection = new Microsoft.Data.SqlClient.SqlConnection(sourceConnectionString);
sourceConnection.Open();
var schema = Execute.readSchema(logger, ReadOptions.Default, sourceConnection);

Execute.generateScriptFiles(ScriptOptions.Default, schema, destinationDirectory);

About

DbFlow is a library that helps with schema oriented database tasks

Resources

License

Stars

6 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors