using Microsoft.Data.Sqlite;
namespace JiDangJia.Server;
public static class ServerProduct
{
#if COMMUNITY_APP
public const string Id="community",Name="寄当家社群",Version="3.1.2",PackageId="com.xfestudio.jidangjia.community",DirectoryName="CommunityServer",Cookie="jdj_community_admin";
#else
public const string Id="accounting",Name="寄当家",Version="3.1.2",PackageId="com.xfestudio.jidangjia",DirectoryName="AccountingServer",Cookie="jdj_accounting_admin";
#endif
internal static void Claim(SqliteConnection connection)
{
// Refuse combined or foreign databases; migration must produce a scoped copy first.
var tables=ServerStore.Rows(connection,"SELECT name FROM sqlite_master WHERE type='table'").Select(r=>ServerStore.Text(r,"name")).ToHashSet();
if(!tables.Contains("ProductIdentity")&&tables.Contains("Accounts"))
throw new InvalidOperationException("检测到旧版合并数据库,请先使用独立迁移工具生成本产品的数据副本,禁止直接共用旧库。");
ServerStore.Exec(connection,"CREATE TABLE IF NOT EXISTS ProductIdentity(id INTEGER PRIMARY KEY CHECK(id=1),product TEXT NOT NULL)");
ServerStore.Exec(connection,"INSERT OR IGNORE INTO ProductIdentity VALUES(1,@p0)",Id);
if(ServerStore.Text(ServerStore.Rows(connection,"SELECT product FROM ProductIdentity WHERE id=1")[0],"product")!=Id)
throw new InvalidOperationException("此数据目录属于另一个 APP,两个后台必须使用不同的数据目录。");
}
}
using Microsoft.Data.Sqlite;
namespace JiDangJia.Server;
public static class ServerProduct
{
#if COMMUNITY_APP
public const string Id="community",Name="寄当家社群",Version="3.1.2",PackageId="com.xfestudio.jidangjia.community",DirectoryName="CommunityServer",Cookie="jdj_community_admin";
#else
public const string Id="accounting",Name="寄当家",Version="3.1.2",PackageId="com.xfestudio.jidangjia",DirectoryName="AccountingServer",Cookie="jdj_accounting_admin";
#endif
internal static void Claim(SqliteConnection connection)
{
// Refuse combined or foreign databases; migration must produce a scoped copy first.
var tables=ServerStore.Rows(connection,"SELECT name FROM sqlite_master WHERE type='table'").Select(r=>ServerStore.Text(r,"name")).ToHashSet();
if(!tables.Contains("ProductIdentity")&&tables.Contains("Accounts"))
throw new InvalidOperationException("检测到旧版合并数据库,请先使用独立迁移工具生成本产品的数据副本,禁止直接共用旧库。");
ServerStore.Exec(connection,"CREATE TABLE IF NOT EXISTS ProductIdentity(id INTEGER PRIMARY KEY CHECK(id=1),product TEXT NOT NULL)");
ServerStore.Exec(connection,"INSERT OR IGNORE INTO ProductIdentity VALUES(1,@p0)",Id);
if(ServerStore.Text(ServerStore.Rows(connection,"SELECT product FROM ProductIdentity WHERE id=1")[0],"product")!=Id)
throw new InvalidOperationException("此数据目录属于另一个 APP,两个后台必须使用不同的数据目录。");
}
}