HostData ayrımı yapıldı.

This commit is contained in:
Sedat Öztürk 2026-05-26 19:49:46 +03:00
parent b38aabb5bd
commit 7d006e0d74
5 changed files with 33 additions and 6 deletions

View file

@ -72,7 +72,7 @@ public class PlatformIdentityDataSeeder : IdentityDataSeeder
Website = PlatformConsts.Branches.BranchWebsite,
IsActive = PlatformConsts.Branches.BranchIsActive,
TenantId = tenantId,
});
}, autoSave: true);
}
var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName));
@ -140,7 +140,7 @@ public class PlatformIdentityDataSeeder : IdentityDataSeeder
BranchId = branchId,
UserId = userId,
TenantId = tenantId
});
}, autoSave: true);
}
}

View file

@ -41,9 +41,8 @@ public class SqlDataSeeder : IDataSeedContributor, ITransientDependency
return;
}
var sqlFiles = Directory.GetFiles(sqlDataPath, "*.sql")
.OrderBy(f => Path.GetFileName(f))
.ToArray();
var isHostSeed = context.TenantId == null;
var sqlFiles = GetSqlFiles(sqlDataPath, isHostSeed);
if (sqlFiles.Length == 0)
{
@ -52,9 +51,10 @@ public class SqlDataSeeder : IDataSeedContributor, ITransientDependency
}
_logger.LogInformation(
"SqlDataSeeder started for provider '{Provider}' from Seeds/{DirectoryName}. {Count} file(s) to be processed.",
"SqlDataSeeder started for provider '{Provider}' from Seeds/{DirectoryName}. Seed target: {SeedTarget}. {Count} file(s) to be processed.",
DefaultDatabaseProvider,
dataDirectoryName,
isHostSeed ? "Host" : "Tenant",
sqlFiles.Length);
var dbContext = await _dbContextProvider.GetDbContextAsync();
@ -111,6 +111,25 @@ public class SqlDataSeeder : IDataSeedContributor, ITransientDependency
: "SqlData";
}
private static string[] GetSqlFiles(string dataDirectoryPath, bool includeHostData)
{
var sqlFiles = Directory.GetFiles(dataDirectoryPath, "*.sql")
.OrderBy(f => Path.GetFileName(f))
.ToList();
if (includeHostData)
{
var hostDataPath = Path.Combine(dataDirectoryPath, "HostData");
if (Directory.Exists(hostDataPath))
{
sqlFiles.AddRange(Directory.GetFiles(hostDataPath, "*.sql")
.OrderBy(f => Path.GetFileName(f)));
}
}
return sqlFiles.ToArray();
}
private static (string Action, string? ObjectName, string? ObjectType) ExtractSqlInfo(string sql)
{
var patterns = new[]

View file

@ -85,10 +85,18 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Seeds\SqlData\HostData\*.sql">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Seeds\PostgresData\*.sql">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Seeds\PostgresData\HostData\*.sql">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>