CUB-29: Create filament inventory database migration

This commit is contained in:
cubecraft-agents[bot]
2026-04-26 13:16:13 +00:00
parent 230c3b295d
commit a0cdacc7be
5 changed files with 2350 additions and 2 deletions

View File

@@ -49,15 +49,26 @@ public abstract class BaseEntityConfiguration<TEntity> : IEntityTypeConfiguratio
}
/// <summary>
/// Converts PascalCase or camelCase to snake_case.
/// Converts PascalCase or camelCase entity name to plural snake_case table name.
/// e.g. MaterialBase → material_bases, AmsSlot → ams_slots
/// </summary>
protected static string ToSnakeCase(string name)
{
return string.Concat(
var snake = string.Concat(
name.Select((ch, i) =>
i > 0 && char.IsUpper(ch) && (char.IsLower(name[i - 1]) || (i + 1 < name.Length && char.IsLower(name[i + 1])))
? "_" + ch
: ch.ToString()))
.ToLowerInvariant();
// Pluralize: add 's' (handles most cases; irregular plurals handled explicitly if needed)
// Special cases: already_plural stays, 'y' → 'ies', 's'/'x'/'ch'/'sh' → 'es'
if (snake.EndsWith("s"))
return snake; // Already plural or ambiguous — leave as-is
if (snake.EndsWith("y") && !snake.EndsWith("ay") && !snake.EndsWith("ey") && !snake.EndsWith("oy") && !snake.EndsWith("uy"))
return snake[..^1] + "ies";
if (snake.EndsWith("x") || snake.EndsWith("ch") || snake.EndsWith("sh"))
return snake + "es";
return snake + "s";
}
}