From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.Share/Data/Script/DataBaseCreator.cs |   76 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Share/Data/Script/DataBaseCreator.cs b/HotelPms.Share/Data/Script/DataBaseCreator.cs
new file mode 100644
index 0000000..3d0532b
--- /dev/null
+++ b/HotelPms.Share/Data/Script/DataBaseCreator.cs
@@ -0,0 +1,76 @@
+using System.Text;
+
+namespace HotelPms.Share.Data.Script;
+
+public class DataBaseCreator
+{
+    /// <summary>
+    /// パーティション作成用SQL
+    /// 数字型(10件) + 日付型(10件)
+    /// </summary>
+    /// <param name="dbPath"></param>
+    /// <param name="dbName"></param>
+    /// <param name="beginDate"></param>
+    /// <returns></returns>
+    public static string CreatePartitionScript(string dbPath, string dbName, DateTime beginDate)
+    {
+        if(!dbPath.EndsWith(Path.DirectorySeparatorChar)){ dbPath += Path.DirectorySeparatorChar; }
+        StringBuilder sql = new StringBuilder();
+
+        //数字型
+        for (int i = 0; i < 10; i++)
+        {
+            sql.AppendLine($"ALTER DATABASE {dbName} ADD FILEGROUP {dbName}_IntFileGroup{(i + 1).ToString().PadLeft(2, '0')}");
+        }
+
+        for (int i = 0; i < 10; i++)
+        {
+            string no = (i + 1).ToString().PadLeft(2, '0');
+            sql.AppendLine($@"ALTER DATABASE {dbName} ADD FILE (NAME=N'{dbName}_IntFileGroup{no}',FILENAME=N'{dbPath}{dbName}_IntFileGroup{no}.ndf',size=10Mb,filegrowth=5mb) TO FILEGROUP {dbName}_IntFileGroup{no}");
+        }
+
+        sql.Append("CREATE PARTITION FUNCTION [IntPartitionFun](int) AS RANGE RIGHT FOR VALUES (1000000");
+        for (int i = 2; i <= 9; i++)
+        {
+            sql.Append($", {i}000000");
+        }
+        sql.AppendLine(")");
+
+        sql.Append($"CREATE PARTITION SCHEME [IntPartitionSchema] AS PARTITION [IntPartitionFun] TO ([{dbName}_IntFileGroup01]");
+        for (int i = 2; i <= 10; i++)
+        {
+            sql.Append($", [{dbName}_IntFileGroup{i.ToString().PadLeft(2, '0')}]");
+        }
+        sql.AppendLine(")");
+        sql.AppendLine("");
+
+        //日付型
+        for (int i = 0; i < 10; i++)
+        {
+            sql.AppendLine($"ALTER DATABASE {dbName} ADD FILEGROUP {dbName}_DateFileGroup{(i + 1).ToString().PadLeft(2, '0')}");
+        }
+
+        for (int i = 0; i < 10; i++)
+        {
+            string no = (i + 1).ToString().PadLeft(2, '0');
+            sql.AppendLine($@"ALTER DATABASE {dbName} ADD FILE (NAME=N'{dbName}_DateFileGroup{no}',FILENAME=N'{dbPath}{dbName}_DateFileGroup{no}.ndf',size=10Mb,filegrowth=5mb) TO FILEGROUP {dbName}_DateFileGroup{no}");
+        }
+
+        int curYear = beginDate.Year;
+        sql.Append($"CREATE PARTITION FUNCTION [DatePartitionFun](Date) AS RANGE RIGHT FOR VALUES ('{curYear}/01/01'");
+        for (int i = 1; i <= 8; i++)
+        {
+            sql.Append($", '{curYear + i}/01/01'");
+        }
+        sql.AppendLine(")");
+
+        sql.Append($"CREATE PARTITION SCHEME [DatePartitionSchema] AS PARTITION [DatePartitionFun] TO ([{dbName}_DateFileGroup01]");
+        for (int i = 2; i <= 10; i++)
+        {
+            sql.Append($", [{dbName}_DateFileGroup{i.ToString().PadLeft(2, '0')}]");
+        }
+        sql.AppendLine(")");
+
+        return sql.ToString();
+    }
+}

--
Gitblit v1.10.0