Skip to content

Commit

Permalink
Merge pull request #577 from Implem/release/1.4.9.0
Browse files Browse the repository at this point in the history
## Added new features / Bug fixed
  • Loading branch information
pierre3 authored Oct 8, 2024
2 parents 198f655 + e3be923 commit 219ea4e
Show file tree
Hide file tree
Showing 247 changed files with 4,691 additions and 6,487 deletions.
1 change: 1 addition & 0 deletions Implem.CodeDefiner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COPY ["Rds/Implem.IRds/Implem.IRds.csproj", "Rds/Implem.IRds/"]
COPY ["Implem.Factory/Implem.Factory.csproj", "Implem.Factory/"]
COPY ["Rds/Implem.PostgreSql/Implem.PostgreSql.csproj", "Rds/Implem.PostgreSql/"]
COPY ["Rds/Implem.SqlServer/Implem.SqlServer.csproj", "Rds/Implem.SqlServer/"]
COPY ["Rds/Implem.MySql/Implem.MySql.csproj", "Rds/Implem.MySql/"]
COPY ["Implem.Pleasanter/Implem.Pleasanter.csproj", "Implem.Pleasanter/"]
RUN dotnet restore "Implem.CodeDefiner/Implem.CodeDefiner.csproj"
COPY . .
Expand Down
5 changes: 5 additions & 0 deletions Implem.CodeDefiner/Functions/Rds/Configurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Implem.IRds;
using Implem.Libraries.Classes;
using Implem.Libraries.Utilities;
using MySqlConnector;
using Npgsql;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -116,6 +117,10 @@ private static void OutputLicenseInfo()
serverName = new NpgsqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).Host;
database = new NpgsqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).Database;
break;
case "MySQL":
serverName = new MySqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).Server;
database = new MySqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).Database;
break;
default:
serverName = new SqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).DataSource;
database = new SqlConnectionStringBuilder(Parameters.Rds.SaConnectionString).InitialCatalog;
Expand Down
8 changes: 8 additions & 0 deletions Implem.CodeDefiner/Functions/Rds/IndexInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,13 @@ internal string IndexName()
.Sha512Cng()
.MaxLength(factory.SqlDefinitionSetting.IdentifierPostfixLength);
}

internal string IndexInfoString()
{
return ColumnCollection
.Where(o => o.No > 0)
.Select(o => o.ColumnName + "," + o.OrderType.ToString())
.Join(",");
}
}
}
4 changes: 2 additions & 2 deletions Implem.CodeDefiner/Functions/Rds/Parts/ColumnSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static bool HasChanges(
}
}

private static bool Char(
internal static bool Char(
ColumnDefinition columnDefinition, DataRow rdsColumn, int coefficient)
{
return rdsColumn["max_length"].ToInt() == -1 && columnDefinition.MaxLength == -1
Expand All @@ -40,7 +40,7 @@ private static bool Char(
: false;
}

private static bool Decimal(
internal static bool Decimal(
ColumnDefinition columnDefinition, DataRow rdsColumn)
{
return rdsColumn["Size"].ToString() != columnDefinition.Size;
Expand Down
60 changes: 50 additions & 10 deletions Implem.CodeDefiner/Functions/Rds/Parts/Columns.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Implem.DefinitionAccessor;
using Implem.CodeDefiner.Functions.Rds.Parts.MySql;
using Implem.DefinitionAccessor;
using Implem.IRds;
using Implem.Libraries.DataSources.SqlServer;
using Implem.Libraries.Utilities;
Expand All @@ -15,7 +16,8 @@ internal static EnumerableRowCollection<DataRow> Get(ISqlObjectFactory factory,
factory: factory,
commandText: Def.Sql.Columns
.Replace("#TableName#", sourceTableName)
.Replace("#SchemaName#", factory.SqlDefinitionSetting.SchemaName))
.Replace("#SchemaName#", factory.SqlDefinitionSetting.SchemaName)
.Replace("#InitialCatalog#", Environments.ServiceName))
.AsEnumerable();
}

Expand All @@ -40,6 +42,32 @@ private static bool HasChanges(
DataRow rdsColumn,
ColumnDefinition columnDefinition)
{
bool ColumnSizeHasChanges()
{
switch (Parameters.Rds.Dbms)
{
case "SQLServer":
case "PostgreSQL":
if (ColumnSize.HasChanges(
factory: factory,
rdsColumn: rdsColumn,
columnDefinition: columnDefinition))
{
return true;
}
break;
case "MySQL":
if (MySqlColumnSize.HasChanges(
factory: factory,
rdsColumn: rdsColumn,
columnDefinition: columnDefinition))
{
return true;
}
break;
}
return false;
}
if (!(rdsColumn["ColumnName"].ToString() == columnDefinition.ColumnName))
{
return true;
Expand All @@ -48,7 +76,7 @@ private static bool HasChanges(
{
return true;
}
if (ColumnSize.HasChanges(factory: factory, rdsColumn: rdsColumn, columnDefinition: columnDefinition))
if (ColumnSizeHasChanges())
{
return true;
}
Expand All @@ -72,13 +100,25 @@ internal static void CreateColumn(
IEnumerable<ColumnDefinition> columnDefinitionCollection)
{
var sqlCreateColumnCollection = new List<string>();
columnDefinitionCollection.ForEach(columnDefinition =>
sqlCreateColumnCollection.Add(Sql_Create(
factory,
columnDefinition,
noIdentity:
sourceTableName.EndsWith("_history")
|| sourceTableName.EndsWith("_deleted"))));
switch (Parameters.Rds.Dbms)
{
case "SQLServer":
case "PostgreSQL":
columnDefinitionCollection.ForEach(columnDefinition =>
sqlCreateColumnCollection.Add(Sql_Create(
factory: factory,
columnDefinition: columnDefinition,
noIdentity:
sourceTableName.EndsWith("_history")
|| sourceTableName.EndsWith("_deleted"))));
break;
case "MySQL":
columnDefinitionCollection.ForEach(columnDefinition =>
sqlCreateColumnCollection.Add(MySqlColumns.Sql_Create(
factory: factory,
columnDefinition: columnDefinition)));
break;
}
sqlStatement.CommandText = sqlStatement.CommandText.Replace(
"#Columns#", sqlCreateColumnCollection.Join(","));
}
Expand Down
71 changes: 61 additions & 10 deletions Implem.CodeDefiner/Functions/Rds/Parts/Constraints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Implem.DefinitionAccessor;
using Implem.CodeDefiner.Functions.Rds.Parts.MySql;
using Implem.DefinitionAccessor;
using Implem.IRds;
using Implem.Libraries.DataSources.SqlServer;
using Implem.Libraries.Utilities;
Expand Down Expand Up @@ -35,22 +36,47 @@ internal static bool HasChanges(
Get(factory: factory, sourceTableName: sourceTableName)
.Where(o => !(sourceTableName.EndsWith("_history") && o["column_name"].ToString() == "Ver"))
.OrderBy(o => o["column_name"])
.Select(o => o["column_name"] + "," + factory.SqlDataType.DefaultDefinition(o["column_default"]))
.Select(o => o["column_name"] + "," + factory.SqlDataType.DefaultDefinition(o))
.JoinReturn();
}

internal static void CreateDefault(
this SqlStatement sqlStatement,
ISqlObjectFactory factory,
string sourceTableName,
string tableNameTemp,
IEnumerable<ColumnDefinition> columnDefinitionCollection)
{
switch (Parameters.Rds.Dbms)
{
case "SQLServer":
case "PostgreSQL":
sqlStatement.CommandText = CreateDefaultCommand(
factory: factory,
tableNameTemp: tableNameTemp,
columnDefinitionCollection: columnDefinitionCollection,
command: sqlStatement.CommandText);
break;
case "MySQL":
sqlStatement.CommandText = MySqlConstraints.CreateModifyColumnCommand(
factory: factory,
tableNameTemp: tableNameTemp,
columnDefinitionCollection: columnDefinitionCollection,
command: sqlStatement.CommandText);
break;
}
}

private static string CreateDefaultCommand(
ISqlObjectFactory factory,
string tableNameTemp,
IEnumerable<ColumnDefinition> columnDefinitionCollection,
string tableNameTemp = "")
string command)
{
sqlStatement.CommandText = sqlStatement.CommandText.Replace(
return command.Replace(
"#Defaults#", columnDefinitionCollection
.Where(o => !o.Default.IsNullOrEmpty())
.Where(o => !(sourceTableName.EndsWith("_history") && o.ColumnName == "Ver"))
.Select(o => Sql_Create(factory, Def.Sql.CreateDefault, Strings.CoalesceEmpty(tableNameTemp, sourceTableName), o))
.Where(o => !(tableNameTemp.EndsWith("_history") && o.ColumnName == "Ver"))
.Select(o => Sql_Create(factory, Def.Sql.CreateDefault, tableNameTemp, o))
.JoinReturn());
}

Expand All @@ -66,7 +92,7 @@ private static string Sql_Create(
.Replace("#DefaultValue#", DefaultDefinition(factory, columnDefinition));
}

private static string DefaultDefinition(ISqlObjectFactory factory, ColumnDefinition columnDefinition)
internal static string DefaultDefinition(ISqlObjectFactory factory, ColumnDefinition columnDefinition)
{
switch (columnDefinition.TypeName.CsTypeSummary())
{
Expand Down Expand Up @@ -94,7 +120,32 @@ internal static void DropConstraint(
string sourceTableName,
IEnumerable<IndexInfo> tableIndexCollection)
{
sqlStatement.CommandText = sqlStatement.CommandText
switch (Parameters.Rds.Dbms)
{
case "SQLServer":
case "PostgreSQL":
sqlStatement.CommandText = DropConstraintCommand(
factory: factory,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection,
command: sqlStatement.CommandText);
break;
case "MySQL":
sqlStatement.CommandText = MySqlConstraints.DropConstraintCommand(
factory: factory,
sourceTableName: sourceTableName,
command: sqlStatement.CommandText);
break;
}
}

private static string DropConstraintCommand(
ISqlObjectFactory factory,
string sourceTableName,
IEnumerable<IndexInfo> tableIndexCollection,
string command)
{
return command
.Replace("#DropConstraint#", tableIndexCollection
.Where(o => Indexes.Get(
factory: factory,
Expand All @@ -106,7 +157,7 @@ internal static void DropConstraint(
.Join("\r\n"));
}

private static string Sql_Drop(IndexInfo o)
internal static string Sql_Drop(IndexInfo o)
{
return o.Type == IndexInfo.Types.Pk
? Def.Sql.DropConstraint
Expand Down
105 changes: 83 additions & 22 deletions Implem.CodeDefiner/Functions/Rds/Parts/Indexes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Implem.DefinitionAccessor;
using Implem.CodeDefiner.Functions.Rds.Parts.MySql;
using Implem.DefinitionAccessor;
using Implem.IRds;
using Implem.Libraries.DataSources.SqlServer;
using Implem.Libraries.Utilities;
Expand All @@ -16,28 +17,60 @@ internal static IEnumerable<IndexInfo> IndexInfoCollection(
Sqls.TableTypes tableType)
{
var tableIndexCollection = new List<IndexInfo>();
switch (tableType)
switch (Parameters.Rds.Dbms)
{
case Sqls.TableTypes.Normal:
General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
Unique(factory: factory,
generalTableName: generalTableName,
tableIndexCollection: tableIndexCollection);
break;
case Sqls.TableTypes.Deleted:
General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
case "SQLServer":
case "PostgreSQL":
switch (tableType)
{
case Sqls.TableTypes.Normal:
General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
Unique(factory: factory,
generalTableName: generalTableName,
tableIndexCollection: tableIndexCollection);
break;
case Sqls.TableTypes.Deleted:
General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
break;
case Sqls.TableTypes.History:
History(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
break;
}
break;
case Sqls.TableTypes.History:
History(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
case "MySQL":
switch (tableType)
{
case Sqls.TableTypes.Normal:
MySqlIndexes.General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
Unique(factory: factory,
generalTableName: generalTableName,
tableIndexCollection: tableIndexCollection);
break;
case Sqls.TableTypes.Deleted:
MySqlIndexes.General(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
break;
case Sqls.TableTypes.History:
MySqlIndexes.History(factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableIndexCollection: tableIndexCollection);
break;
}
break;
}
return tableIndexCollection;
Expand Down Expand Up @@ -182,7 +215,9 @@ public static IEnumerable<string> Get(ISqlObjectFactory factory, string sourceTa
{
return Def.SqlIoByAdmin(factory: factory).ExecuteTable(
factory: factory,
commandText: Def.Sql.Indexes.Replace("#TableName#", sourceTableName))
commandText: Def.Sql.Indexes
.Replace("#TableName#", sourceTableName)
.Replace("#InitialCatalog#", Environments.ServiceName))
.AsEnumerable()
.Select(o => o["Name"].ToString())
.Distinct()
Expand All @@ -194,6 +229,32 @@ internal static bool HasChanges(
string generalTableName,
string sourceTableName,
Sqls.TableTypes tableType)
{
switch (Parameters.Rds.Dbms)
{
case "SQLServer":
case "PostgreSQL":
return HasChangesPkIx(
factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableType: tableType);
case "MySQL":
return MySqlIndexes.HasChangesPkIx(
factory: factory,
generalTableName: generalTableName,
sourceTableName: sourceTableName,
tableType: tableType);
default:
return false;
}
}

private static bool HasChangesPkIx(
ISqlObjectFactory factory,
string generalTableName,
string sourceTableName,
Sqls.TableTypes tableType)
{
if (Parameters.Rds.DisableIndexChangeDetection)
{
Expand Down
Loading

0 comments on commit 219ea4e

Please sign in to comment.