From e80e939edab7fe3f331a151a547c4c6af9d7b240 Mon Sep 17 00:00:00 2001 From: blattersturm Date: Sat, 25 May 2019 12:03:13 +0200 Subject: [PATCH] add readme --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea978a7 --- /dev/null +++ b/README.md @@ -0,0 +1,80 @@ +# FxMigrant +_automated database migrations for CitizenFX servers_ + +## Installation +1. Download the latest release from GitHub releases. +2. Extract it someplace in your resources directory. +3. Currently, only MySQL is supported. Use a valid MySQLConnector connection string as `mysql_connection_string` convar. Typically, `mysql-async` already uses this kind of string. +4. Run a resource that uses FxMigrant. + +Currently (2019-05-25), it's unlikely for Linux servers to work with this as-is, this might need either a new artifact build or the usual copying of CitizenFX.Core.Server.dll. + +## Building +1. Clone the repository. +2. Make sure you have .NET Core SDK installed. +3. Run build.ps1. + +## Using +Reference [FluentMigrator](https://fluentmigrator.github.io/) migration .cs files in your \_\_resource.lua: + +```lua +migration_files { + 'migrations/0001_create_users.cs', + 'migrations/0002_add_license.cs +} + +dependency 'fxmigrant' + +server_script '@fxmigrant/helper.lua' +``` + +Also, instead of `MySQL.ready`, use `Migrant.ready`. + +Example files to show the point: + +### 0001_create_users.cs +```cs +using FluentMigrator; + +[Migration(1)] +public class CreateUsers : Migration +{ + public override void Up() + { + Create.Table("users") + .WithColumn("identifier").AsString().NotNullable().PrimaryKey() + .WithColumn("money").AsInt64().Nullable() + .WithColumn("bank").AsInt64().Nullable() + .WithColumn("permission_level").AsInt32().Nullable() + .WithColumn("group").AsString().Nullable(); + } + + public override void Down() + { + Delete.Table("users"); + } +} +``` + +### 0002_add_license.cs +```cs +using FluentMigrator; + +[Migration(2)] +public class AddLicense : Migration +{ + public override void Up() + { + Create.Column("license") + .OnTable("users") + .AsString() + .Nullable() + .WithDefaultValue(""); + } + + public override void Down() + { + Delete.Column("license").FromTable("users"); + } +} +``` \ No newline at end of file