A few weeks ago, I was looking into making a change to a project in work that uses DbUp. For some reason, I took away from that the overwhelming urge to write my own data generator. It’s far from finished, but I came up with datagen. This currently only comes in a MySql flavour, but my plan is to add a few more database engines.
The idea behind this is that you can generate pseudo data in your database. It’s not a tool in its own right, because I wanted to allow it to be customisable. To install , simply reference the package:
<PackageReference Include="datagen.MySql" Version="1.0.0" />
You can then populate the data in an entire schema. Just create a console app (this works with any app type that can physically access the database):
using datagen.Core; using datagen.MySql; using datagen.MySql.MySql; var valueGenerator = new ValueGenerator( true, DateTime.Now, DateTime.Now.AddDays(-100), DateTime.Now.AddDays(10)); string connectionString = "Server=127.0.0.1;Port=3306;Database=datagentest;Uid=root;Pwd=password;AllowUserVariables=True"; var mySqlDefaults = new MySqlDefaults(connectionString); var generate = new Generate( connectionString, valueGenerator, mySqlDefaults.DataTypeParser, mySqlDefaults .UniqueKeyGenerator); await generate.FillSchema(20, "datagentest");
The code above allows you to create a ValueGenerator – there is a default one in the package, but you can easily write your own. FillSchema then adds 20 rows to every table in the schema.
There are currently a few limitations – the main two being that this will only work with MySql currently, and that it does not deal with foreign keys (it will just omit that data).
Feel free to contribute, offer suggestions, or contibute.