Skip to content

chore: replace sqlite fork#29493

Merged
andig merged 10 commits intomasterfrom
chore/sqlite
Apr 30, 2026
Merged

chore: replace sqlite fork#29493
andig merged 10 commits intomasterfrom
chore/sqlite

Conversation

@andig
Copy link
Copy Markdown
Member

@andig andig commented Apr 29, 2026

Follow-up to #29301

TODO

Out of scope

  • WAL mode (with backup)

@andig andig added the infrastructure Basic functionality label Apr 29, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Since the SQLite driver has been swapped out, double-check that any driver-specific behavior (DSN format, pragmas, busy timeout / WAL settings, and default transaction behavior) provided by the previous fork is either preserved or explicitly reconfigured with github.com/libtnb/sqlite to avoid subtle runtime differences.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the SQLite driver has been swapped out, double-check that any driver-specific behavior (DSN format, pragmas, busy timeout / WAL settings, and default transaction behavior) provided by the previous fork is either preserved or explicitly reconfigured with github.com/libtnb/sqlite to avoid subtle runtime differences.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@andig
Copy link
Copy Markdown
Member Author

andig commented Apr 29, 2026

@naltatis this fails TestCloseSessionsOnStartup which it shouldn't and/or our expectation might be brittle?

@naltatis
Copy link
Copy Markdown
Member

It also fails backup/restore where we check that a saved title is restored from backup.

    [chromium] › tests/backup-restore.spec.ts:109:3 › backup and restore › download backup and restore from file 

Does not look like brittle expectation, more like a real issue.

@andig
Copy link
Copy Markdown
Member Author

andig commented Apr 29, 2026

Can we find out why? Looks like a proper library, I'd expect it to actually work :O

@naltatis
Copy link
Copy Markdown
Member

Looks like two issue. The driver uses another string time format: 0001-01-01T00:00:00Z instead of previously 0001-01-01 00:00:00+00:00. That's why the unit test fails.

The integration test fails because of the addition of journal_mode(WAL). This breaks our backup mechanism where we close db and simply copy evcc.db. With WAL multiple files are created that we would have to take care of. Reverting this.

@naltatis
Copy link
Copy Markdown
Member

Regarding time string format: I'm unsure if the new format would create issues or if GORM will simply convert both (old and new) to proper time. However, this mix would lead to inconsistency in raw data.

@andig
Copy link
Copy Markdown
Member Author

andig commented Apr 29, 2026

With WAL multiple files are created that we would have to take care of. Reverting this.

Ok. I always assumed WAL mode is the default. We should re-add this and do a SQL export instead. There's also a dedicated backup api (https://sqlite.org/backup.html), let's see if that's supported here.

@naltatis
Copy link
Copy Markdown
Member

Bildschirmfoto 2026-04-29 um 20 38 31

Just did a functional check. Both time formats seem to be readable, but I'm really confused by this new length date format. Maybe it's time to also switch to unix timestamp here to get rid of this topic :D

@naltatis
Copy link
Copy Markdown
Member

We should re-add this and do a SQL export instead.

+1, but sounds like a topic for a dedicate PR

@andig
Copy link
Copy Markdown
Member Author

andig commented Apr 29, 2026

@naltatis added draft backup. Agreed this is only needed for WAL mode. Might move to dedicated function and keep nonetheless.

@andig andig marked this pull request as draft April 29, 2026 19:26
@andig
Copy link
Copy Markdown
Member Author

andig commented Apr 30, 2026

Time should be fixed- let's see whats missing now.

@andig andig marked this pull request as ready for review April 30, 2026 09:59
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="server/db/db.go" line_range="118-124" />
<code_context>
 	return db.Close()
 }
+
+func Backup(ctx context.Context, target string) error {
+	live, err := Instance.DB()
+	if err != nil {
+		return err
+	}
+
+	conn, err := live.Conn(ctx)
+	if err != nil {
+		return err
</code_context>
<issue_to_address>
**issue (bug_risk):** The *sql.Conn acquired in Backup is never closed, which can leak connections.

After `live.Conn(ctx)` succeeds, ensure the returned `*sql.Conn` is closed (e.g., `defer conn.Close()`) after `conn.Raw(...)` completes. Leaving it open for the process lifetime can exhaust the connection pool and underlying resources over time.
</issue_to_address>

### Comment 2
<location path="server/db/db.go" line_range="129-133" />
<code_context>
+		return err
+	}
+
+	return conn.Raw(func(driverConn any) error {
+		type backuper interface {
+			NewBackup(string) (*sqlite3.Backup, error)
+			NewRestore(string) (*sqlite3.Backup, error)
+		}
+
</code_context>
<issue_to_address>
**suggestion:** The backuper interface includes NewRestore but it is never used.

You can narrow the `backuper` interface to only `NewBackup`. Leaving `NewRestore` unused makes the assertion more restrictive than needed and more fragile if the driver changes.

```suggestion
	return conn.Raw(func(driverConn any) error {
		type backuper interface {
			NewBackup(string) (*sqlite3.Backup, error)
		}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread server/db/db.go
Comment thread server/db/db.go
Copy link
Copy Markdown
Member

@naltatis naltatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@andig andig merged commit 66ff40d into master Apr 30, 2026
12 checks passed
@andig andig deleted the chore/sqlite branch April 30, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure Basic functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants