Skip to content

Add PebbleDB backend with migration#65

Merged
jdfalk merged 3 commits intomainfrom
codex/build-database-with-pebbledb-integration
Jun 8, 2025
Merged

Add PebbleDB backend with migration#65
jdfalk merged 3 commits intomainfrom
codex/build-database-with-pebbledb-integration

Conversation

@jdfalk
Copy link
Copy Markdown
Owner

@jdfalk jdfalk commented Jun 8, 2025

Summary

  • implement SubtitleStore interface with SQLite and Pebble implementations
  • allow choosing backend via new --db-backend flag
  • add migration command and functions to move data from SQLite to Pebble
  • document backend selection and migration steps

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_6845d83256808321bf7000209224bf9f

@jdfalk jdfalk added the codex Created or modified by AI/automation agents label Jun 8, 2025 — with ChatGPT Codex Connector
@jdfalk jdfalk requested a review from Copilot June 8, 2025 20:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a PebbleDB backend alongside the existing SQLite store, adds a factory and migration command, and updates the CLI, tests, and docs to support choosing between backends.

  • Define and wire up a SubtitleStore interface with OpenStore factory
  • Implement PebbleStore (with tests) and a MigrateToPebble function (with tests)
  • Update SQL store, CLI commands, docs, and dependencies for backend selection and migration

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/database/store_factory.go Add OpenStore factory to select SQLite or Pebble by flag
pkg/database/store.go Define the SubtitleStore interface
pkg/database/pebble.go Implement PebbleStore with JSON storage, List, Delete, etc.
pkg/database/pebble_test.go Unit tests for PebbleStore insert/list and delete
pkg/database/migrate.go Add MigrateToPebble to copy data from SQLite to PebbleDB
pkg/database/migrate_test.go Test the migration of records from SQLite to Pebble
pkg/database/database.go Refactor SQL store into SQLStore, add new fields and methods
pkg/database/database_test.go Update legacy tests to new InsertSubtitle signature
cmd/translate.go Use OpenStore and new SubtitleStore API in translate cmd
cmd/root.go Add --db-backend flag and bind to Viper
cmd/migrate.go Add migrate Cobra command for SQLite→Pebble migration
cmd/history.go Switch history command to use OpenStore and interface methods
cmd/delete.go Switch delete command to use OpenStore and interface methods
go.mod Add Pebble and related deps (cockroachdb/pebble, google/uuid)
docs/TECHNICAL_DESIGN.md Document new backend option and updated schema functions
README.md Update usage docs for --db-backend and migrate command
CHANGELOG.md Record new PebbleDB backend version bump
TODO.md Note completion of PebbleDB work
Comments suppressed due to low confidence (1)

pkg/database/database.go:125

  • There are no unit tests for the new SQLStore methods (InsertSubtitle, ListSubtitles, DeleteSubtitle). Add tests that exercise those methods and verify the schema and data round-trip.
func (s *SQLStore) InsertSubtitle(rec *SubtitleRecord) error {

Comment thread pkg/database/database.go
}

// OpenSQLStore opens or creates an SQLite database and returns a SQLStore.
func OpenSQLStore(path string) (*SQLStore, error) {
Copy link

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

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

OpenSQLStore never calls initSchema to create or migrate the SQLite schema, so tables won’t exist on first use. Add a call to initSchema(s.db) after opening the database.

Copilot uses AI. Check for mistakes.
Comment thread cmd/translate.go Outdated
Comment thread pkg/database/pebble.go Outdated
Comment thread pkg/database/database.go
Comment on lines +160 to 165
// InsertSubtitle stores a new subtitle record with associated metadata.
func InsertSubtitle(db *sql.DB, file, video, lang, service, release string, embedded bool) error {
_, err := db.Exec(`INSERT INTO subtitles (file, video_file, release, language, service, embedded, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
file, video, release, lang, service, boolToInt(embedded), time.Now())
return err
}
Copy link

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

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

[nitpick] The free function InsertSubtitle overlaps with the SQLStore method and has a long argument list, which can be confusing. Consider deprecating or renaming legacy functions and consolidating to the SubtitleStore interface.

Suggested change
// InsertSubtitle stores a new subtitle record with associated metadata.
func InsertSubtitle(db *sql.DB, file, video, lang, service, release string, embedded bool) error {
_, err := db.Exec(`INSERT INTO subtitles (file, video_file, release, language, service, embedded, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
file, video, release, lang, service, boolToInt(embedded), time.Now())
return err
}
// Deprecated: Use SQLStore.InsertSubtitle instead.
// func InsertSubtitle(db *sql.DB, file, video, lang, service, release string, embedded bool) error {
// _, err := db.Exec(`INSERT INTO subtitles (file, video_file, release, language, service, embedded, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
// file, video, release, lang, service, boolToInt(embedded), time.Now())
// return err
// }

Copilot uses AI. Check for mistakes.
jdfalk and others added 2 commits June 8, 2025 16:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jdfalk jdfalk merged commit cdb8ad9 into main Jun 8, 2025
1 check failed
@jdfalk jdfalk deleted the codex/build-database-with-pebbledb-integration branch June 8, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Created or modified by AI/automation agents

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants