ss14-databases
БесплатноБез исполняемых скриптовНе проверенSS14 Database System Guide (PostgreSQL and SQLite)
от makura-games★ 74 звезды на GitHubОб этом скилле
🗄️ Databases SS14 (Databases)
This skill describes the database architecture in Space Station 14, including dual engine support (PostgreSQL and SQLite), DbContext inheritance, and best practices for data models.
🎯 When to use this skill
- When creating new tables or database entities.
- When changing existing data models.
- When writing requests to obtain or save player data, bans or logs.
- When solving problems related to data types (IP addresses, JSON, etc.).
🏗️ Architecture Review
SS14 uses Entity Framework Core with a dual engine architecture to support both PostgreSQL (production) and SQLite (dev/test).
Key Components
IServerDbManager: The main interface for database operations (Content.Server/Database/ServerDbManager.cs).ServerDbBase: Abstract base class containing common logic for both engines.ServerDbSqliteandServerDbPostgres: Specific implementations for specific engines.ServerDbContext: An abstract EF Core context that definesDbSet's.SqliteServerDbContextandPostgresServerDbContext: Specific contexts that manage configuration (for example, Value Converters).
Database Logic vs Models
- Logic: Located in
Content.Server/Database. ContainsServerDbManager,ServerDbBase, etc. - Models: Found in
Content.Server.Database. ContainsModel.cs(tables), migrations, and context definitions.
📝 Working with Data Models
Defining Entities
Entities are defined in Content.Server.Database/Model.cs (or in separate files in that namespace).
public class MyNewEntity
{
[Key] // Primary key
public int Id { get; set; }
[Required] // This field is required
public string Name { get; set; } = default!;
// Foreign key or just user ID
public Guid PlayerUserId { get; set; }
}
Adding to Context
Add DbSet to the abstract ServerDbContext to Content.Server.Database/Model.cs:
public abstract class ServerDbContext : DbContext
{
// ... existing sets
public DbSet<MyNewEntity> MyNewEntities { get; set; } = default!;
}
⚠️ Engine Limitations and Data Types
Since SQLite and PostgreSQL support different functions, you need to be careful with types.
1. IP addresses 🌐
- Postgres: Has native type
inet(NpgsqlInet). - SQLite: Doesn't support IP. Must be stored as
TEXT. - Solution: Use
ValueConverterinSqliteServerDbContext.OnModelCreating.
2. JSON Data 📜
- Postgres: Has the native type
jsonb. - SQLite: Must be stored as
TEXTorBLOB. - Solution: Use separate calls to
db.PgDbContext.Add()anddb.SqliteDbContext.Add()if complex types are used, or ValueConverters for shared logic.
3. Arrays/Lists 📚
- Postgres: Supports primitive arrays (for example,
List<string>maps totext[]). - SQLite: Does not support arrays.
- Solution:
- Preferred: Use a separate table with a 1:N relationship.
- Alternative: Serialize the string to JSON (if you don't need to search inside the list).
💡 Usage Examples
1. Data Saving (Difference Handling)
When saving data that uses specific types (like IP), you may need to override the method in ServerDbSqlite and ServerDbPostgres.
Abstract Base (ServerDbBase.cs):
public abstract Task AddServerBanAsync(ServerBanDef serverBan);
Postgres implementation (ServerDbPostgres.cs):
public override async Task AddServerBanAsync(ServerBanDef serverBan)
{
await using var db = await GetDbImpl();
// Postgres supports NpgsqlInet directly, no conversion needed
db.PgDbContext.Ban.Add(new ServerBan
{
Address = serverBan.Address.ToNpgsqlInet(),
// ... other fields
});
await db.PgDbContext.SaveChangesAsync();
}
SQLite implementation (ServerDbSqlite.cs):
public override async Task AddServerBanAsync(ServerBanDef serverBan)
{
await using var db = await GetDbImpl();
// SQLite requires a conversion, which is handled by the ValueConverter in context
db.SqliteDbContext.Ban.Add(new ServerBan
{
Address = serverBan.Address.ToNpgsqlInet(),
// ... other fields
});
await db.SqliteDbContext.SaveChangesAsync();
}
2. Data Loading (General Logic)
Reading data is often identical for both engines and can be implemented in ServerDbBase.
// Content.Server/Database/ServerDbBase.cs
public async Task<PlayerPreferences?> GetPlayerPreferencesAsync(NetUserId userId, CancellationToken cancel)
{
await using var db = await GetDb(cancel);
// Using .Include() to greedily load related data
var prefs = await db.DbContext
.Preference
.Include(p => p.Profiles)
.ThenInclude(h => h.Jobs) // Loading nested links (Profiles -> Jobs)
.AsSplitQuery() // Optimization: Avoids "explosion" of the Cartesian product with multiple include
.SingleOrDefaultAsync(p =
Установить ss14-databases в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ss14-databases?
SS14 Database System Guide (PostgreSQL and SQLite)
Как установить скилл ss14-databases?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ss14-databases запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic