-
Notifications
You must be signed in to change notification settings - Fork 39
/
MySqlMigrationConsole.cs
61 lines (54 loc) · 3.65 KB
/
MySqlMigrationConsole.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
using CoreEx;
using Microsoft.Extensions.Logging;
using System;
using System.Reflection;
namespace Beef.Database.MySql
{
/// <summary>
/// Provides the SQL Server migration console capability.
/// </summary>
/// <param name="args">The default <see cref="MigrationArgs"/> that will be overridden/updated by the command-line argument values.</param>
public class MySqlMigrationConsole(MigrationArgs? args = null) : MigrationConsoleBase<MySqlMigrationConsole>(args)
{
/// <summary>
/// Creates a new <see cref="MySqlMigrationConsole"/> using <typeparamref name="T"/> to default the probing <see cref="Assembly"/>.
/// </summary>
/// <typeparam name="T">The <see cref="Type"/>.</typeparam>
/// <param name="connectionString">The database connection string.</param>
/// <returns>A new <see cref="MySqlMigrationConsole"/>.</returns>
public static MySqlMigrationConsole Create<T>(string connectionString) => new(new MigrationArgs { ConnectionString = connectionString }.AddAssembly(typeof(T).Assembly));
/// <summary>
/// Creates a new instance of the <see cref="MySqlMigrationConsole"/> class using the specified parameters.
/// </summary>
/// <param name="connectionString">The default connection string.</param>
/// <param name="company">The company name.</param>
/// <param name="appName">The application/domain name.</param>
/// <returns>The <see cref="MySqlMigrationConsole"/> instance.</returns>
public static MySqlMigrationConsole Create(string connectionString, string company, string appName)
=> new(new MigrationArgs { ConnectionString = connectionString.ThrowIfNull(nameof(connectionString)) }
.AddParameter(CodeGen.CodeGenConsole.CompanyParamName, company.ThrowIfNull(nameof(company)))
.AddParameter(CodeGen.CodeGenConsole.AppNameParamName, appName.ThrowIfNull(nameof(appName))));
/// <summary>
/// Initializes a new instance of the <see cref="MySqlMigrationConsole"/> class that provides a default for the <paramref name="connectionString"/>.
/// </summary>
/// <param name="connectionString">The database connection string.</param>
public MySqlMigrationConsole(string connectionString) : this(new MigrationArgs { ConnectionString = connectionString.ThrowIfNull(nameof(connectionString)) }) { }
/// <inheritdoc/>
protected override DbEx.Migration.DatabaseMigrationBase CreateMigrator() => new MySqlMigration(Args);
/// <inheritdoc/>
public override string AppTitle => base.AppTitle + " [MySQL]";
/// <inheritdoc/>
protected override void OnWriteHelp()
{
base.OnWriteHelp();
new DbEx.MySql.Console.MySqlMigrationConsole(new DbEx.Migration.MigrationArgs { Logger = Logger }).WriteScriptHelp();
Logger?.LogInformation("{help}", string.Empty);
Logger?.LogInformation("{help}", "Extended CodeGen command and argument(s):");
Logger?.LogInformation("{help}", " codegen yaml <Table> [<Table>...] Creates a temporary Beef entity code-gen YAML file for the specified table(s).");
Logger?.LogInformation("{help}", " - A table name with a prefix ! denotes that no CRUD operations are required.");
Logger?.LogInformation("{help}", " - A table name with a prefix * denotes that a 'GetByArgs' operation is required.");
Logger?.LogInformation("{help}", string.Empty);
}
}
}