From adba974a4bc5e9a508f157658607bc656dfbf502 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Wed, 8 Apr 2026 22:14:07 +0200 Subject: [PATCH] fix(repos): use new table name in repo and tests --- persistence/migrations/003_link.sql | 6 +++--- persistence/repositories/note_repository.go | 2 +- persistence/repositories/tag_repository.go | 6 +++--- test/test_integration/create_note_handler_test.go | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/persistence/migrations/003_link.sql b/persistence/migrations/003_link.sql index a7b77ec..10e39da 100644 --- a/persistence/migrations/003_link.sql +++ b/persistence/migrations/003_link.sql @@ -6,9 +6,9 @@ CREATE TABLE IF NOT EXISTS link ( raw TEXT NOT NULL, line INTEGER NOT NULL, col INTEGER NOT NULL, - FOREIGN KEY(from_note_id) REFERENCES note(id) ON DELETE CASCADE, + FOREIGN KEY(from_note_id) REFERENCES note(id) ON DELETE CASCADE ); -CREATE INDEX idx_link_from ON links(from_note_id); -CREATE INDEX idx_link_target ON links(target_slug); +CREATE INDEX idx_link_from ON link(from_note_id); +CREATE INDEX idx_link_target ON link(target_slug); diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go index e7d3425..e7fc96e 100644 --- a/persistence/repositories/note_repository.go +++ b/persistence/repositories/note_repository.go @@ -21,7 +21,7 @@ func NewNoteRepository(tx *sql.Tx) NoteRepository { func (r *noteRepository) Upsert(ctx context.Context, note *models.Note) error { query := ` - INSERT INTO notes (id, title, path, slug, created_at, updated_at) + INSERT INTO note (id, title, path, slug, created_at, updated_at) VALUES (?, ?, ?, ?, datetime('now'), datetime('now')) ON CONFLICT (slug) DO UPDATE SET title = EXCLUDED.title, diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go index 27fcd2f..e73663c 100644 --- a/persistence/repositories/tag_repository.go +++ b/persistence/repositories/tag_repository.go @@ -35,7 +35,7 @@ func (r *tagRepository) Upsert(ctx context.Context, tags []*models.Tag) error { args = append(args, tag.ID(), tag.Name()) } - query := "INSERT OR IGNORE INTO tags(id, name) VALUES " + strings.Join(placeholders, ",") + query := "INSERT OR IGNORE INTO tag(id, name) VALUES " + strings.Join(placeholders, ",") _, err := r.Transaction.ExecContext(ctx, query, args...) return err @@ -54,7 +54,7 @@ func (r *tagRepository) UpsertNoteTags(ctx context.Context ,noteID string, tagID args = append(args, noteID, tagID) } - query := "INSERT OR IGNORE INTO note_tags(note_id, tag_id) VALUES " + strings.Join(placeholders, ",") + query := "INSERT OR IGNORE INTO note_tag(note_id, tag_id) VALUES " + strings.Join(placeholders, ",") _, err := r.Transaction.ExecContext(ctx, query, args...) if err != nil { @@ -77,7 +77,7 @@ func (r *tagRepository) GetByNames(ctx context.Context, names []string) ([]*mode args = append(args, name) } - query := "SELECT id, name FROM tags WHERE name IN (" + strings.Join(placeholders, ",") + ")" + query := "SELECT id, name FROM tag WHERE name IN (" + strings.Join(placeholders, ",") + ")" rows, err := r.Transaction.QueryContext(ctx, query, args...) if err != nil { diff --git a/test/test_integration/create_note_handler_test.go b/test/test_integration/create_note_handler_test.go index ec71470..c964129 100644 --- a/test/test_integration/create_note_handler_test.go +++ b/test/test_integration/create_note_handler_test.go @@ -31,7 +31,7 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T assert.Equal(t, notePath, result) var count int - require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "my-note").Scan(&count)) + require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "my-note").Scan(&count)) assert.Equal(t, 1, count) _, statErr := os.Stat(notePath) @@ -68,10 +68,10 @@ func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t assert.Equal(t, notePath, result) var noteCount int - require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "templated-note").Scan(¬eCount)) + require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "templated-note").Scan(¬eCount)) assert.Equal(t, 1, noteCount) - rows, err := Fixture.DB.Query(`SELECT name FROM tags WHERE name IN ('go', 'testing')`) + rows, err := Fixture.DB.Query(`SELECT name FROM tag WHERE name IN ('go', 'testing')`) require.NoError(t, err) defer rows.Close() @@ -112,12 +112,12 @@ func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) { require.NoError(t, err) var count int - require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "dup-note").Scan(&count)) + require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "dup-note").Scan(&count)) assert.Equal(t, 1, count) expectedPath := filepath.Join(vaultPath, subDir2, "dup-note.md") var path string - require.NoError(t, Fixture.DB.QueryRow(`SELECT path FROM notes WHERE slug = ?`, "dup-note").Scan(&path)) + require.NoError(t, Fixture.DB.QueryRow(`SELECT path FROM note WHERE slug = ?`, "dup-note").Scan(&path)) assert.Equal(t, expectedPath, path) }