Files
YKanBan/YKanBan/Storage/Workspace/WorkspacePreset.cs
T
yyc12345 31fc58d9c7 feat(m1): storage layer
- Shared SQLite plumbing: PRAGMAs (WAL/NORMAL/foreign_keys) and
  user_version migrations with typed SchemaVersionException
- Workspace folder: .ykanban initialization, empty schema with
  DDL-level constraints, preset column seeding (ResX-driven),
  exclusive lock file with holder diagnostics
- AppData folder: app.db workspace registry (injectable clock),
  app.json config store with kebab-case JSON names via explicit
  [JsonProperty]/[EnumMember], nested sections, corrupt-file backup
- ResX infrastructure under Assets/Locales (en + zh-Hans) with
  MSBuild strongly-typed public Resources class
- 54 unit tests: DDL constraints, migrations, PRAGMAs, lock
  exclusivity, config degradation, culture-aware presets
2026-10-01 18:17:47 +08:00

47 lines
1.8 KiB
C#

using Microsoft.Data.Sqlite;
namespace YKanBan.Storage.Workspace;
/// <summary>
/// Seeds initial workspace content. The three preset column titles are read
/// straight from the ResX resources in the UI language active at seeding
/// time, then stored as ordinary data that no longer follows language
/// switches.
/// </summary>
public static class WorkspacePreset
{
/// <summary>Inserts the three preset columns (To Do / In Progress / Done equivalents).</summary>
/// <exception cref="SqliteException">A title collides with an existing column.</exception>
public static void SeedColumns(string folderPath)
{
using SqliteConnection connection = SqliteDatabase.Open(
WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
long now = UnixTime.Now;
// Preset titles are data at creation time: whatever the current language says gets stored.
string[] titles =
[
Resources.PresetColumn_Todo,
Resources.PresetColumn_InProgress,
Resources.PresetColumn_Done,
];
// Insert all three in one transaction so a half-seeded workspace can never exist.
using var transaction = connection.BeginTransaction();
foreach (string title in titles)
{
using var command = connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = """
INSERT INTO columns (title, description, created_at, updated_at)
VALUES ($title, '', $now, $now);
""";
command.Parameters.AddWithValue("$title", title);
command.Parameters.AddWithValue("$now", now);
command.ExecuteNonQuery();
}
transaction.Commit();
}
}