Files
pages/internal/db/migrate_test.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

45 lines
1.2 KiB
Go

package db
import (
"path/filepath"
"testing"
)
func TestRevisionMetadataMigrationIsRecorded(t *testing.T) {
database, err := Open(filepath.Join(t.TempDir(), "pages.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.Close() })
if err := Migrate(database); err != nil {
t.Fatal(err)
}
var applied int
if err := database.QueryRow(`
SELECT count(*)
FROM schema_migrations
WHERE name = 'revision_metadata_v1'
`).Scan(&applied); err != nil {
t.Fatal(err)
}
if applied != 1 {
t.Fatalf("migration marker count = %d, want 1", applied)
}
// Simulate a deployment which applied the data backfill before the index
// was introduced. A completed migration must not skip missing indexes.
if _, err := database.Exec(`DROP INDEX idx_revisions_object_created`); err != nil {
t.Fatal(err)
}
if err := Migrate(database); err != nil {
t.Fatalf("second migration run failed: %v", err)
}
var indexes int
if err := database.QueryRow(`SELECT count(*) FROM sqlite_master WHERE type='index' AND name='idx_revisions_object_created'`).Scan(&indexes); err != nil {
t.Fatal(err)
}
if indexes != 1 {
t.Fatal("missing revision index after migration")
}
}