Skip to content

feat(database): resolve relative SQLite paths against RootDirectory#26

Merged
tgiachi merged 2 commits into
developfrom
feature/sqlite-rootdir
Jul 2, 2026
Merged

feat(database): resolve relative SQLite paths against RootDirectory#26
tgiachi merged 2 commits into
developfrom
feature/sqlite-rootdir

Conversation

@tgiachi

@tgiachi tgiachi commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

A relative SQLite path in database.ConnectionString (e.g. sqlite://app.db) is now resolved against SquidStd's RootDirectory (via DirectoriesConfig.Root), consistent with how the log directory already behaves — instead of resolving verbatim against the process CWD. The DB file's folder is created if missing.

Absolute paths, :memory:, and server providers (postgres/mysql/mssql) are unchanged. The parser stays verbatim when called without a base directory (back-compat).

Changes

  • ParsedConnection: new SqliteFilePath (resolved on-disk path; null for :memory:/server).
  • ConnectionStringParser.Parse(cs, sqliteBaseDirectory?): resolves relative SQLite paths against the base.
  • DatabaseService: injects DirectoriesConfig, passes Root, ensures the DB folder exists.

Test Plan

  • Parser: relative+base resolves; absolute/:memory:/no-base/server unchanged (5 new tests)
  • DatabaseService: relative sqlite://sub/app.db creates <root>/sub on StartAsync
  • Full suite: 985/985 green; build 0 errors, 0 new warnings


if (!Path.IsPathRooted(remainder) && !string.IsNullOrWhiteSpace(baseDirectory))
{
return Path.GetFullPath(Path.Combine(baseDirectory, remainder));
[Fact]
public void Parse_SqliteRelativePath_WithBaseDirectory_ResolvesAgainstBase()
{
var baseDir = Path.Combine(Path.GetTempPath(), "squidstd-base");
var baseDir = Path.Combine(Path.GetTempPath(), "squidstd-base");
var result = ConnectionStringParser.Parse("sqlite://app.db", baseDir);

var expected = Path.GetFullPath(Path.Combine(baseDir, "app.db"));
[Fact]
public async Task StartAsync_RelativeSqlitePathWithSubdirectory_CreatesDirectoryUnderRoot()
{
var root = Path.Combine(Path.GetTempPath(), "squidstd-root-" + Guid.NewGuid().ToString("N"));
{
await service.StartAsync();

Assert.True(Directory.Exists(Path.Combine(root, "sub")));
@tgiachi
tgiachi merged commit 1db4d90 into develop Jul 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants