Fix migrazione dati key INT

This commit is contained in:
Samuele Locatelli
2024-01-15 14:47:13 +01:00
parent dc3bd557d2
commit 7a62ecbbd5
8 changed files with 55 additions and 29 deletions
@@ -72,7 +72,7 @@ namespace MagMan.Data.Admin.Controllers
.DbSetAuthKey
.Where(x => CustomerId == 0 || x.CustomerID == CustomerId)
.Include(c => c.CustomerNav)
.OrderBy(x => x.KeyName)
.OrderBy(x => x.KeyNum)
.ToList();
}
return dbResult;
@@ -96,7 +96,7 @@ namespace MagMan.Data.Admin.Controllers
.FirstOrDefault();
if (currData != null)
{
currData.KeyName = updItem.KeyName;
currData.KeyNum = updItem.KeyNum;
currData.KeyValue = updItem.KeyValue;
currData.Note = updItem.Note;
currData.CustomerID = updItem.CustomerID;
+9 -7
View File
@@ -2,6 +2,7 @@
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -62,28 +63,29 @@ namespace MagMan.Data.Admin
return answ;
}
public static bool CheckCreateCustDb(string nKeyMain)
public static bool CheckCreateCustDb(int nKeyMain)
{
bool answ = false;
string dbName = $"MagMan_{nKeyMain}";
string dbName = $"MagMan_{nKeyMain:000000}";
using (ServerAdminContext adbCtx = new ServerAdminContext())
{
// ricerca DB...
string sqlCommand = $"SHOW DATABASES LIKE '%{nKeyMain}';";
string sqlCommand = $"SHOW DATABASES;";
var searchDb = adbCtx
.DbList
.FromSqlRaw(sqlCommand)
.FirstOrDefault();
// se trovato ok
.ToList();
// se trovato qualcosa procedo
if (searchDb != null)
{
answ = true;
var rigaDb = searchDb.Where(x => x.Database.Contains(dbName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
answ = rigaDb != null;
}
// altrimenti crea
if (!answ)
{
// creo DB
sqlCommand = $"CREATE DATABASE [IF NOT EXISTS] MagMan_{nKeyMain};";
sqlCommand = $"CREATE DATABASE IF NOT EXISTS {dbName};";
adbCtx.Database.ExecuteSqlRaw(sqlCommand);
}
}
+6
View File
@@ -45,6 +45,12 @@ namespace MagMan.Data.Admin
return DbAdmin.CheckCreateUser(DATABASE_USER, DATABASE_PWD, DATABASE_NAME);
}
public static bool CheckCustDb(int masterKey)
{
// esecuzione script di install locale
return DbAdmin.CheckCreateCustDb(masterKey);
}
public static bool ExecMigrationIdentity()
{
// esecuzione migrazione
+2 -2
View File
@@ -26,9 +26,9 @@ namespace MagMan.Data.Admin.DbModels
public int CustomerID { get; set; } = 0;
/// <summary>
/// Nome
/// Numero chiave
/// </summary>
public string KeyName { get; set; } = "";
public int KeyNum { get; set; } = 0;
/// <summary>
/// Nome
+1 -1
View File
@@ -48,7 +48,7 @@ namespace MagMan.Data.Admin.DbModels
/// <summary>
/// Chiave principale (impianto) associata
/// </summary>
public string MainKey { get; set; } = "";
public int MainKey { get; set; } = 0;
/// <summary>
/// Boolean di creazione DB
@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace MagMan.Data.Admin.Migrations
{
[DbContext(typeof(MultiTenantContext))]
[Migration("20240115100646_MachineKeyAndDb")]
[Migration("20240115132229_MachineKeyAndDb")]
partial class MachineKeyAndDb
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -36,9 +36,8 @@ namespace MagMan.Data.Admin.Migrations
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("KeyName")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("KeyNum")
.HasColumnType("int");
b.Property<string>("KeyValue")
.IsRequired()
@@ -98,9 +97,8 @@ namespace MagMan.Data.Admin.Migrations
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("MainKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("MainKey")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
@@ -8,6 +8,10 @@ namespace MagMan.Data.Admin.Migrations
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "KeyName",
table: "AuthKeyList");
migrationBuilder.AddColumn<bool>(
name: "HasDb",
table: "MachineList",
@@ -15,12 +19,19 @@ namespace MagMan.Data.Admin.Migrations
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
migrationBuilder.AddColumn<int>(
name: "MainKey",
table: "MachineList",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "KeyNum",
table: "AuthKeyList",
type: "int",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
@@ -32,6 +43,17 @@ namespace MagMan.Data.Admin.Migrations
migrationBuilder.DropColumn(
name: "MainKey",
table: "MachineList");
migrationBuilder.DropColumn(
name: "KeyNum",
table: "AuthKeyList");
migrationBuilder.AddColumn<string>(
name: "KeyName",
table: "AuthKeyList",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
}
}
}
@@ -34,9 +34,8 @@ namespace MagMan.Data.Admin.Migrations
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("KeyName")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("KeyNum")
.HasColumnType("int");
b.Property<string>("KeyValue")
.IsRequired()
@@ -96,9 +95,8 @@ namespace MagMan.Data.Admin.Migrations
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("MainKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("MainKey")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()