fix(favorites): satisfy persistence lint
- commit
- 3991a6ee51c895d45512a9a86db3e3edbe6fe294
- author
- brice · · 2026-06-28 08:12 UTC
- parent
- 8f314a2
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +39 -22
M internal/infrastructure/persistence/sqlite/favorite_repo.go +24 -6
| @@ -189,26 +189,41 @@ func favoriteFromRow(row favoriteRow, target *entity.Favorite) *entity.Favorite | |||
| 189 | 189 | } | |
| 190 | 190 | ||
| 191 | 191 | func favoriteRowFromCreate(row sqlc.CreateFavoriteRow) favoriteRow { | |
| 192 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | |
| 192 | + | return favoriteRow{ | |
| 193 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 194 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 195 | + | } | |
| 193 | 196 | } | |
| 194 | 197 | ||
| 195 | 198 | func favoriteRowFromGetByID(row sqlc.GetFavoriteByIDRow) favoriteRow { | |
| 196 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | |
| 199 | + | return favoriteRow{ | |
| 200 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 201 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 202 | + | } | |
| 197 | 203 | } | |
| 198 | 204 | ||
| 199 | 205 | func favoriteRowFromGetByURL(row sqlc.GetFavoriteByURLRow) favoriteRow { | |
| 200 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | |
| 206 | + | return favoriteRow{ | |
| 207 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 208 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 209 | + | } | |
| 201 | 210 | } | |
| 202 | 211 | ||
| 203 | 212 | func favoriteRowFromGetByShortcut(row sqlc.GetFavoriteByShortcutRow) favoriteRow { | |
| 204 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | |
| 213 | + | return favoriteRow{ | |
| 214 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 215 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 216 | + | } | |
| 205 | 217 | } | |
| 206 | 218 | ||
| 207 | 219 | func favoritesFromAllRows(rows []sqlc.GetAllFavoritesRow) []*entity.Favorite { | |
| 208 | 220 | favorites := make([]*entity.Favorite, len(rows)) | |
| 209 | 221 | for i := range rows { | |
| 210 | 222 | row := rows[i] | |
| 211 | - | favorites[i] = favoriteFromRow(favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt}, nil) | |
| 223 | + | favorites[i] = favoriteFromRow(favoriteRow{ | |
| 224 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 225 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 226 | + | }, nil) | |
| 212 | 227 | } | |
| 213 | 228 | return favorites | |
| 214 | 229 | } | |
| @@ -217,7 +232,10 @@ func favoritesFromTagRows(rows []sqlc.GetFavoritesByTagRow) []*entity.Favorite { | |||
| 217 | 232 | favorites := make([]*entity.Favorite, len(rows)) | |
| 218 | 233 | for i := range rows { | |
| 219 | 234 | row := rows[i] | |
| 220 | - | favorites[i] = favoriteFromRow(favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt}, nil) | |
| 235 | + | favorites[i] = favoriteFromRow(favoriteRow{ | |
| 236 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |
| 237 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |
| 238 | + | }, nil) | |
| 221 | 239 | } | |
| 222 | 240 | return favorites | |
| 223 | 241 | } | |
| @@ -189,26 +189,41 @@ func favoriteFromRow(row favoriteRow, target *entity.Favorite) *entity.Favorite | |||||
| 189 | } | 189 | } | ||
| 190 | 190 | ||||
| 191 | func favoriteRowFromCreate(row sqlc.CreateFavoriteRow) favoriteRow { | 191 | func favoriteRowFromCreate(row sqlc.CreateFavoriteRow) favoriteRow { | ||
| 192 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | 192 | + | return favoriteRow{ |
| 193 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 194 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 195 | + | } | |||
| 193 | } | 196 | } | ||
| 194 | 197 | ||||
| 195 | func favoriteRowFromGetByID(row sqlc.GetFavoriteByIDRow) favoriteRow { | 198 | func favoriteRowFromGetByID(row sqlc.GetFavoriteByIDRow) favoriteRow { | ||
| 196 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | 199 | + | return favoriteRow{ |
| 200 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 201 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 202 | + | } | |||
| 197 | } | 203 | } | ||
| 198 | 204 | ||||
| 199 | func favoriteRowFromGetByURL(row sqlc.GetFavoriteByURLRow) favoriteRow { | 205 | func favoriteRowFromGetByURL(row sqlc.GetFavoriteByURLRow) favoriteRow { | ||
| 200 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | 206 | + | return favoriteRow{ |
| 207 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 208 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 209 | + | } | |||
| 201 | } | 210 | } | ||
| 202 | 211 | ||||
| 203 | func favoriteRowFromGetByShortcut(row sqlc.GetFavoriteByShortcutRow) favoriteRow { | 212 | func favoriteRowFromGetByShortcut(row sqlc.GetFavoriteByShortcutRow) favoriteRow { | ||
| 204 | - | return favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt} | 213 | + | return favoriteRow{ |
| 214 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 215 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 216 | + | } | |||
| 205 | } | 217 | } | ||
| 206 | 218 | ||||
| 207 | func favoritesFromAllRows(rows []sqlc.GetAllFavoritesRow) []*entity.Favorite { | 219 | func favoritesFromAllRows(rows []sqlc.GetAllFavoritesRow) []*entity.Favorite { | ||
| 208 | favorites := make([]*entity.Favorite, len(rows)) | 220 | favorites := make([]*entity.Favorite, len(rows)) | ||
| 209 | for i := range rows { | 221 | for i := range rows { | ||
| 210 | row := rows[i] | 222 | row := rows[i] | ||
| 211 | - | favorites[i] = favoriteFromRow(favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt}, nil) | 223 | + | favorites[i] = favoriteFromRow(favoriteRow{ |
| 224 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 225 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 226 | + | }, nil) | |||
| 212 | } | 227 | } | ||
| 213 | return favorites | 228 | return favorites | ||
| 214 | } | 229 | } | ||
| @@ -217,7 +232,10 @@ func favoritesFromTagRows(rows []sqlc.GetFavoritesByTagRow) []*entity.Favorite { | |||||
| 217 | favorites := make([]*entity.Favorite, len(rows)) | 232 | favorites := make([]*entity.Favorite, len(rows)) | ||
| 218 | for i := range rows { | 233 | for i := range rows { | ||
| 219 | row := rows[i] | 234 | row := rows[i] | ||
| 220 | - | favorites[i] = favoriteFromRow(favoriteRow{ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt}, nil) | 235 | + | favorites[i] = favoriteFromRow(favoriteRow{ |
| 236 | + | ID: row.ID, URL: row.Url, Title: row.Title, FaviconURL: row.FaviconUrl, | |||
| 237 | + | ShortcutKey: row.ShortcutKey, Position: row.Position, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, | |||
| 238 | + | }, nil) | |||
| 221 | } | 239 | } | ||
| 222 | return favorites | 240 | return favorites | ||
| 223 | } | 241 | } | ||
M internal/infrastructure/persistence/sqlite/favorite_repo_test.go +4 -4
| @@ -23,12 +23,12 @@ func openFavoriteRepoTestDB(t *testing.T) *sql.DB { | |||
| 23 | 23 | return db | |
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | - | func seedFavoriteWithTags(t *testing.T, db *sql.DB) (entity.FavoriteID, entity.FavoriteID, entity.TagID) { | |
| 26 | + | func seedFavoriteWithTags(t *testing.T, db *sql.DB) (entity.FavoriteID, entity.TagID) { | |
| 27 | 27 | t.Helper() | |
| 28 | 28 | mustExec(t, db, `INSERT INTO favorites(id, url, title, shortcut_key, position) VALUES (1, 'https://one.example', 'One', 1, 1), (2, 'https://two.example', 'Two', NULL, 2)`) | |
| 29 | 29 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'research', '#111111'), (2, 'engines', '#222222')`) | |
| 30 | 30 | mustExec(t, db, `INSERT INTO favorite_tag_assignments(favorite_id, tag_id) VALUES (1, 1), (1, 2), (2, 1)`) | |
| 31 | - | return 1, 2, 1 | |
| 31 | + | return 1, 1 | |
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | func TestFavoriteRepositoryGetAllHydratesTags(t *testing.T) { | |
| @@ -49,7 +49,7 @@ func TestFavoriteRepositoryGetAllHydratesTags(t *testing.T) { | |||
| 49 | 49 | ||
| 50 | 50 | func TestFavoriteRepositoryFindByIDHydratesTags(t *testing.T) { | |
| 51 | 51 | db := openFavoriteRepoTestDB(t) | |
| 52 | - | favID, _, _ := seedFavoriteWithTags(t, db) | |
| 52 | + | favID, _ := seedFavoriteWithTags(t, db) | |
| 53 | 53 | repo := NewFavoriteRepository(db) | |
| 54 | 54 | ||
| 55 | 55 | fav, err := repo.FindByID(context.Background(), favID) | |
| @@ -73,7 +73,7 @@ func TestFavoriteRepositoryFindByURLHydratesTags(t *testing.T) { | |||
| 73 | 73 | ||
| 74 | 74 | func TestFavoriteRepositoryGetByTagHydratesTags(t *testing.T) { | |
| 75 | 75 | db := openFavoriteRepoTestDB(t) | |
| 76 | - | _, _, tagID := seedFavoriteWithTags(t, db) | |
| 76 | + | _, tagID := seedFavoriteWithTags(t, db) | |
| 77 | 77 | repo := NewFavoriteRepository(db) | |
| 78 | 78 | ||
| 79 | 79 | favorites, err := repo.GetByTag(context.Background(), tagID) | |
| @@ -23,12 +23,12 @@ func openFavoriteRepoTestDB(t *testing.T) *sql.DB { | |||||
| 23 | return db | 23 | return db | ||
| 24 | } | 24 | } | ||
| 25 | 25 | ||||
| 26 | - | func seedFavoriteWithTags(t *testing.T, db *sql.DB) (entity.FavoriteID, entity.FavoriteID, entity.TagID) { | 26 | + | func seedFavoriteWithTags(t *testing.T, db *sql.DB) (entity.FavoriteID, entity.TagID) { |
| 27 | t.Helper() | 27 | t.Helper() | ||
| 28 | mustExec(t, db, `INSERT INTO favorites(id, url, title, shortcut_key, position) VALUES (1, 'https://one.example', 'One', 1, 1), (2, 'https://two.example', 'Two', NULL, 2)`) | 28 | mustExec(t, db, `INSERT INTO favorites(id, url, title, shortcut_key, position) VALUES (1, 'https://one.example', 'One', 1, 1), (2, 'https://two.example', 'Two', NULL, 2)`) | ||
| 29 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'research', '#111111'), (2, 'engines', '#222222')`) | 29 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'research', '#111111'), (2, 'engines', '#222222')`) | ||
| 30 | mustExec(t, db, `INSERT INTO favorite_tag_assignments(favorite_id, tag_id) VALUES (1, 1), (1, 2), (2, 1)`) | 30 | mustExec(t, db, `INSERT INTO favorite_tag_assignments(favorite_id, tag_id) VALUES (1, 1), (1, 2), (2, 1)`) | ||
| 31 | - | return 1, 2, 1 | 31 | + | return 1, 1 |
| 32 | } | 32 | } | ||
| 33 | 33 | ||||
| 34 | func TestFavoriteRepositoryGetAllHydratesTags(t *testing.T) { | 34 | func TestFavoriteRepositoryGetAllHydratesTags(t *testing.T) { | ||
| @@ -49,7 +49,7 @@ func TestFavoriteRepositoryGetAllHydratesTags(t *testing.T) { | |||||
| 49 | 49 | ||||
| 50 | func TestFavoriteRepositoryFindByIDHydratesTags(t *testing.T) { | 50 | func TestFavoriteRepositoryFindByIDHydratesTags(t *testing.T) { | ||
| 51 | db := openFavoriteRepoTestDB(t) | 51 | db := openFavoriteRepoTestDB(t) | ||
| 52 | - | favID, _, _ := seedFavoriteWithTags(t, db) | 52 | + | favID, _ := seedFavoriteWithTags(t, db) |
| 53 | repo := NewFavoriteRepository(db) | 53 | repo := NewFavoriteRepository(db) | ||
| 54 | 54 | ||||
| 55 | fav, err := repo.FindByID(context.Background(), favID) | 55 | fav, err := repo.FindByID(context.Background(), favID) | ||
| @@ -73,7 +73,7 @@ func TestFavoriteRepositoryFindByURLHydratesTags(t *testing.T) { | |||||
| 73 | 73 | ||||
| 74 | func TestFavoriteRepositoryGetByTagHydratesTags(t *testing.T) { | 74 | func TestFavoriteRepositoryGetByTagHydratesTags(t *testing.T) { | ||
| 75 | db := openFavoriteRepoTestDB(t) | 75 | db := openFavoriteRepoTestDB(t) | ||
| 76 | - | _, _, tagID := seedFavoriteWithTags(t, db) | 76 | + | _, tagID := seedFavoriteWithTags(t, db) |
| 77 | repo := NewFavoriteRepository(db) | 77 | repo := NewFavoriteRepository(db) | ||
| 78 | 78 | ||||
| 79 | favorites, err := repo.GetByTag(context.Background(), tagID) | 79 | favorites, err := repo.GetByTag(context.Background(), tagID) | ||
M internal/infrastructure/persistence/sqlite/favorites_migration_test.go +11 -12
| @@ -3,7 +3,6 @@ package sqlite | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | "database/sql" | |
| 6 | - | "fmt" | |
| 7 | 6 | "testing" | |
| 8 | 7 | ||
| 9 | 8 | _ "github.com/bnema/purego-sqlite/driver" | |
| @@ -21,15 +20,15 @@ func openMigrationTestDB(t *testing.T) *sql.DB { | |||
| 21 | 20 | return db | |
| 22 | 21 | } | |
| 23 | 22 | ||
| 24 | - | func runMigrationsUpTo(t *testing.T, db *sql.DB, version int64) { | |
| 23 | + | func runMigrationsThroughFavoritesSchema(t *testing.T, db *sql.DB) { | |
| 25 | 24 | t.Helper() | |
| 26 | 25 | goose.SetBaseFS(embedMigrations) | |
| 27 | 26 | if err := goose.SetDialect("sqlite3"); err != nil { | |
| 28 | 27 | t.Fatalf("set dialect: %v", err) | |
| 29 | 28 | } | |
| 30 | 29 | goose.SetLogger(goose.NopLogger()) | |
| 31 | - | if err := goose.UpTo(db, "migrations", version); err != nil { | |
| 32 | - | t.Fatalf("migrate to %d: %v", version, err) | |
| 30 | + | if err := goose.UpTo(db, "migrations", 10); err != nil { | |
| 31 | + | t.Fatalf("migrate through favorites schema: %v", err) | |
| 33 | 32 | } | |
| 34 | 33 | } | |
| 35 | 34 | ||
| @@ -51,7 +50,7 @@ func countRows(t *testing.T, db *sql.DB, query string, args ...any) int { | |||
| 51 | 50 | ||
| 52 | 51 | func TestFavoritesTagsFirstMigrationFolderPathToTag(t *testing.T) { | |
| 53 | 52 | db := openMigrationTestDB(t) | |
| 54 | - | runMigrationsUpTo(t, db, 10) | |
| 53 | + | runMigrationsThroughFavoritesSchema(t, db) | |
| 55 | 54 | ||
| 56 | 55 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (1, 'Research', NULL), (2, 'Browser Engines', 1)`) | |
| 57 | 56 | mustExec(t, db, `INSERT INTO favorites(id, url, title, folder_id) VALUES (1, 'https://webkit.org', 'WebKit', 2)`) | |
| @@ -69,7 +68,7 @@ func TestFavoritesTagsFirstMigrationFolderPathToTag(t *testing.T) { | |||
| 69 | 68 | ||
| 70 | 69 | func TestFavoritesTagsFirstMigrationFolderTagCollisionSuffix(t *testing.T) { | |
| 71 | 70 | db := openMigrationTestDB(t) | |
| 72 | - | runMigrationsUpTo(t, db, 10) | |
| 71 | + | runMigrationsThroughFavoritesSchema(t, db) | |
| 73 | 72 | ||
| 74 | 73 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'dev-go', '#111111')`) | |
| 75 | 74 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (7, 'Dev', NULL), (8, 'Go', 7)`) | |
| @@ -88,7 +87,7 @@ func TestFavoritesTagsFirstMigrationFolderTagCollisionSuffix(t *testing.T) { | |||
| 88 | 87 | ||
| 89 | 88 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsExistingTag(t *testing.T) { | |
| 90 | 89 | db := openMigrationTestDB(t) | |
| 91 | - | runMigrationsUpTo(t, db, 10) | |
| 90 | + | runMigrationsThroughFavoritesSchema(t, db) | |
| 92 | 91 | ||
| 93 | 92 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111'), (2, 'foo-folder-3', '#222222')`) | |
| 94 | 93 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL)`) | |
| @@ -107,7 +106,7 @@ func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsExistingTag(t *testing. | |||
| 107 | 106 | ||
| 108 | 107 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsFolderNaturalSlug(t *testing.T) { | |
| 109 | 108 | db := openMigrationTestDB(t) | |
| 110 | - | runMigrationsUpTo(t, db, 10) | |
| 109 | + | runMigrationsThroughFavoritesSchema(t, db) | |
| 111 | 110 | ||
| 112 | 111 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111')`) | |
| 113 | 112 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL), (4, 'foo-folder-3', NULL)`) | |
| @@ -134,7 +133,7 @@ func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsFolderNaturalSlug(t *te | |||
| 134 | 133 | ||
| 135 | 134 | func TestFavoritesTagsFirstMigrationMergesFoldedDuplicateTags(t *testing.T) { | |
| 136 | 135 | db := openMigrationTestDB(t) | |
| 137 | - | runMigrationsUpTo(t, db, 10) | |
| 136 | + | runMigrationsThroughFavoritesSchema(t, db) | |
| 138 | 137 | ||
| 139 | 138 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, ' Dev-Go ', '#111111'), (2, 'dev-go', '#222222')`) | |
| 140 | 139 | mustExec(t, db, `INSERT INTO favorites(id, url, title) VALUES (1, 'https://one.example', 'One'), (2, 'https://two.example', 'Two')`) | |
| @@ -154,9 +153,9 @@ func TestFavoritesTagsFirstMigrationMergesFoldedDuplicateTags(t *testing.T) { | |||
| 154 | 153 | } | |
| 155 | 154 | } | |
| 156 | 155 | ||
| 157 | - | func mustExec(t *testing.T, db *sql.DB, query string, args ...any) { | |
| 156 | + | func mustExec(t *testing.T, db *sql.DB, query string) { | |
| 158 | 157 | t.Helper() | |
| 159 | - | if _, err := db.Exec(query, args...); err != nil { | |
| 160 | - | t.Fatalf("exec %s: %v", fmt.Sprintf(query, args...), err) | |
| 158 | + | if _, err := db.Exec(query); err != nil { | |
| 159 | + | t.Fatalf("exec %s: %v", query, err) | |
| 161 | 160 | } | |
| 162 | 161 | } | |
| @@ -3,7 +3,6 @@ package sqlite | |||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | "database/sql" | 5 | "database/sql" | ||
| 6 | - | "fmt" | |||
| 7 | "testing" | 6 | "testing" | ||
| 8 | 7 | ||||
| 9 | _ "github.com/bnema/purego-sqlite/driver" | 8 | _ "github.com/bnema/purego-sqlite/driver" | ||
| @@ -21,15 +20,15 @@ func openMigrationTestDB(t *testing.T) *sql.DB { | |||||
| 21 | return db | 20 | return db | ||
| 22 | } | 21 | } | ||
| 23 | 22 | ||||
| 24 | - | func runMigrationsUpTo(t *testing.T, db *sql.DB, version int64) { | 23 | + | func runMigrationsThroughFavoritesSchema(t *testing.T, db *sql.DB) { |
| 25 | t.Helper() | 24 | t.Helper() | ||
| 26 | goose.SetBaseFS(embedMigrations) | 25 | goose.SetBaseFS(embedMigrations) | ||
| 27 | if err := goose.SetDialect("sqlite3"); err != nil { | 26 | if err := goose.SetDialect("sqlite3"); err != nil { | ||
| 28 | t.Fatalf("set dialect: %v", err) | 27 | t.Fatalf("set dialect: %v", err) | ||
| 29 | } | 28 | } | ||
| 30 | goose.SetLogger(goose.NopLogger()) | 29 | goose.SetLogger(goose.NopLogger()) | ||
| 31 | - | if err := goose.UpTo(db, "migrations", version); err != nil { | 30 | + | if err := goose.UpTo(db, "migrations", 10); err != nil { |
| 32 | - | t.Fatalf("migrate to %d: %v", version, err) | 31 | + | t.Fatalf("migrate through favorites schema: %v", err) |
| 33 | } | 32 | } | ||
| 34 | } | 33 | } | ||
| 35 | 34 | ||||
| @@ -51,7 +50,7 @@ func countRows(t *testing.T, db *sql.DB, query string, args ...any) int { | |||||
| 51 | 50 | ||||
| 52 | func TestFavoritesTagsFirstMigrationFolderPathToTag(t *testing.T) { | 51 | func TestFavoritesTagsFirstMigrationFolderPathToTag(t *testing.T) { | ||
| 53 | db := openMigrationTestDB(t) | 52 | db := openMigrationTestDB(t) | ||
| 54 | - | runMigrationsUpTo(t, db, 10) | 53 | + | runMigrationsThroughFavoritesSchema(t, db) |
| 55 | 54 | ||||
| 56 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (1, 'Research', NULL), (2, 'Browser Engines', 1)`) | 55 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (1, 'Research', NULL), (2, 'Browser Engines', 1)`) | ||
| 57 | mustExec(t, db, `INSERT INTO favorites(id, url, title, folder_id) VALUES (1, 'https://webkit.org', 'WebKit', 2)`) | 56 | mustExec(t, db, `INSERT INTO favorites(id, url, title, folder_id) VALUES (1, 'https://webkit.org', 'WebKit', 2)`) | ||
| @@ -69,7 +68,7 @@ func TestFavoritesTagsFirstMigrationFolderPathToTag(t *testing.T) { | |||||
| 69 | 68 | ||||
| 70 | func TestFavoritesTagsFirstMigrationFolderTagCollisionSuffix(t *testing.T) { | 69 | func TestFavoritesTagsFirstMigrationFolderTagCollisionSuffix(t *testing.T) { | ||
| 71 | db := openMigrationTestDB(t) | 70 | db := openMigrationTestDB(t) | ||
| 72 | - | runMigrationsUpTo(t, db, 10) | 71 | + | runMigrationsThroughFavoritesSchema(t, db) |
| 73 | 72 | ||||
| 74 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'dev-go', '#111111')`) | 73 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'dev-go', '#111111')`) | ||
| 75 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (7, 'Dev', NULL), (8, 'Go', 7)`) | 74 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (7, 'Dev', NULL), (8, 'Go', 7)`) | ||
| @@ -88,7 +87,7 @@ func TestFavoritesTagsFirstMigrationFolderTagCollisionSuffix(t *testing.T) { | |||||
| 88 | 87 | ||||
| 89 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsExistingTag(t *testing.T) { | 88 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsExistingTag(t *testing.T) { | ||
| 90 | db := openMigrationTestDB(t) | 89 | db := openMigrationTestDB(t) | ||
| 91 | - | runMigrationsUpTo(t, db, 10) | 90 | + | runMigrationsThroughFavoritesSchema(t, db) |
| 92 | 91 | ||||
| 93 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111'), (2, 'foo-folder-3', '#222222')`) | 92 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111'), (2, 'foo-folder-3', '#222222')`) | ||
| 94 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL)`) | 93 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL)`) | ||
| @@ -107,7 +106,7 @@ func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsExistingTag(t *testing. | |||||
| 107 | 106 | ||||
| 108 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsFolderNaturalSlug(t *testing.T) { | 107 | func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsFolderNaturalSlug(t *testing.T) { | ||
| 109 | db := openMigrationTestDB(t) | 108 | db := openMigrationTestDB(t) | ||
| 110 | - | runMigrationsUpTo(t, db, 10) | 109 | + | runMigrationsThroughFavoritesSchema(t, db) |
| 111 | 110 | ||||
| 112 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111')`) | 111 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, 'foo', '#111111')`) | ||
| 113 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL), (4, 'foo-folder-3', NULL)`) | 112 | mustExec(t, db, `INSERT INTO favorite_folders(id, name, parent_id) VALUES (3, 'Foo', NULL), (4, 'foo-folder-3', NULL)`) | ||
| @@ -134,7 +133,7 @@ func TestFavoritesTagsFirstMigrationGeneratedSuffixAvoidsFolderNaturalSlug(t *te | |||||
| 134 | 133 | ||||
| 135 | func TestFavoritesTagsFirstMigrationMergesFoldedDuplicateTags(t *testing.T) { | 134 | func TestFavoritesTagsFirstMigrationMergesFoldedDuplicateTags(t *testing.T) { | ||
| 136 | db := openMigrationTestDB(t) | 135 | db := openMigrationTestDB(t) | ||
| 137 | - | runMigrationsUpTo(t, db, 10) | 136 | + | runMigrationsThroughFavoritesSchema(t, db) |
| 138 | 137 | ||||
| 139 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, ' Dev-Go ', '#111111'), (2, 'dev-go', '#222222')`) | 138 | mustExec(t, db, `INSERT INTO favorite_tags(id, name, color) VALUES (1, ' Dev-Go ', '#111111'), (2, 'dev-go', '#222222')`) | ||
| 140 | mustExec(t, db, `INSERT INTO favorites(id, url, title) VALUES (1, 'https://one.example', 'One'), (2, 'https://two.example', 'Two')`) | 139 | mustExec(t, db, `INSERT INTO favorites(id, url, title) VALUES (1, 'https://one.example', 'One'), (2, 'https://two.example', 'Two')`) | ||
| @@ -154,9 +153,9 @@ func TestFavoritesTagsFirstMigrationMergesFoldedDuplicateTags(t *testing.T) { | |||||
| 154 | } | 153 | } | ||
| 155 | } | 154 | } | ||
| 156 | 155 | ||||
| 157 | - | func mustExec(t *testing.T, db *sql.DB, query string, args ...any) { | 156 | + | func mustExec(t *testing.T, db *sql.DB, query string) { |
| 158 | t.Helper() | 157 | t.Helper() | ||
| 159 | - | if _, err := db.Exec(query, args...); err != nil { | 158 | + | if _, err := db.Exec(query); err != nil { |
| 160 | - | t.Fatalf("exec %s: %v", fmt.Sprintf(query, args...), err) | 159 | + | t.Fatalf("exec %s: %v", query, err) |
| 161 | } | 160 | } | ||
| 162 | } | 161 | } | ||