SQL ➜ C# migration code generator for Unity and beyond.
sqlinity turns raw .sql files into C# classes with clean version tracking — making SQLite schema migrations easy to manage in Unity, or any project using embedded C# and SQLite.
Inspired by Goose, built as an internal tool for Unity's ecosystem where no solid schema migration tooling exists but can be used for anything C#.
- CLI command to create new migrations with auto-incrementing numbers
- Converts
.up.sql/.down.sqlfiles into Unity-friendly.csfiles - Auto-generates a
MigrationRegistry.csfile for easy runtime access - Clean, no-runtime-dependency codegen
- Compatible with
sqlite-netand other embedded SQLite libs
Using a sqlite database in a Unity project - although useful - seems niche
For that reason, there's virtually no (at least I couldn't find any) easy to use migration tools for a sqlite + Unity workflow This tool fills that gap — letting you manage database evolution in a way that’s versioned, testable, and game-friendly.
git clone https://github.com/mwac-dev/sqlinity
cd sqlinity
go build -o sqlinityWindows: Move sqlinity.exe somewhere like C:\Tools\sqlinity\ and add that folder to your System PATH
macOS/Linux: Move the binary to /usr/local/bin (or wherever you want and add to PATH)
Now you can run sqlinity from anywhere in your terminal.
my-unity-project/
├── sqlinity.config.json
├── migrations/
│ ├── 001_create_players.up.sql
│ ├── 001_create_players.down.sql
│ └── ...
├── Assets/
│ └── Scripts/
│ └── GeneratedMigrations/Create a sqlinity.config.json file in your project root:
{
"sqlFolder": "./migrations",
"outputFolder": "./Assets/Scripts/GeneratedMigrations",
"namespace": "MyGame.Database.Migrations"
}sqlinity create "create leaderboard table"This will create:
migrations/003_create_leaderboard_table.up.sql
migrations/003_create_leaderboard_table.down.sqlMigration files will auto increment based on the existing files in the migrations directory.
sqlinity generateOutputs:
- Migration_003_create_leaderboard_table.cs
- MigrationRegistry.cs
Example MigrationRegistry.cs:
public static class MigrationRegistry {
public static readonly List<(string Name, string Sql)> Migrations = new() {
(Migration_001_create_players.Name, Migration_001_create_players.Up),
(Migration_002_add_score.Name, Migration_002_add_score.Up),
(Migration_003_create_leaderboard_table.Name, Migration_003_create_leaderboard_table.Up)
};
}Use sqlite-net or similar with a startup script
public static class SqliteMigrationRunner
{
public static void RunMigrations(SQLiteConnection conn)
{
conn.Execute(@"
CREATE TABLE IF NOT EXISTS __migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
");
var applied = new HashSet<string>(
conn.Query<string>("SELECT name FROM __migrations")
);
foreach (var (name, sql) in MigrationRegistry.Migrations)
{
if (applied.Contains(name)) continue;
conn.Execute(sql);
conn.Execute("INSERT INTO __migrations (name) VALUES (?)", name);
}
}
}This ensures your user's local DB is always up to date with migrations when the app launches
File names must follow this structure:
NNN_descriptive_name.up.sql
NNN_descriptive_name.down.sql (optional)
i.e.
001_create_players.up.sql
001_create_players.down.sql- .down.sql is optional — useful for dev resets but not so much at runtime (usually you want to ever migrate up/forward with any changes)
- Migrations are static .sql files — no parameters or dynamic values
- Generated C# files are safe to commit — they are your runtime format - just don't manually edit them, if you NEED to change them, edit the related .sql file and then re-generate using the tool
-
Migration file parser
-
CLI create command
-
C# class generation for each migration
-
Auto-generated MigrationRegistry.cs
-
Editor integration for Unity
-
--config flag support
Use it in your games and tools if you want! Hopefully you find it useful for your use cases.
Tool comes with no warranties - as always use at your own risk and make sure to double check and test all sql queries locally before pushing a build to clients!