feat(store): default auto_summarize ON for new users (ADR-018)
Migration 011 flips the auto_summarize column default to TRUE and brings existing rows (maintainer + current registrations) along. Onboarded friends now get zero-friction discovery: scheduled discovery (ADR-018) both discovers AND summarizes new videos, so a user's list fills and summarizes itself instead of presenting an empty list of manual Summarize buttons. Safe only because the process-wide caption-fetch rate gate (ADR-014 item 2, prior commit) now exists — auto + scheduled + multi-user would otherwise self-inflict 429s every cycle. The down migration reverts the default but intentionally leaves existing rows as-is (no surprise manual regression on rollback). RegisterUser already lets the column default drive the value, so no app change is needed; the account-page manual toggle still works. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,13 +49,44 @@ func loginEventsExists(t *testing.T) bool {
|
||||
// production during a rollback. The test restores the schema to latest before
|
||||
// returning so the shared embedded-postgres stays at HEAD for sibling tests.
|
||||
func TestMigration010LoginEventsUpDown(t *testing.T) {
|
||||
newStore(t) // ensure the schema is migrated to latest (010 applied)
|
||||
newStore(t) // ensure the schema is migrated to latest (011 applied)
|
||||
require.True(t, loginEventsExists(t), "login_events must exist at latest migration")
|
||||
|
||||
m := fileMigrator(t)
|
||||
require.NoError(t, m.Steps(-1), "down one migration must drop login_events")
|
||||
// 011 (auto_summarize default) sits above 010; step it down first so the
|
||||
// 010 down/up is exercised in isolation.
|
||||
require.NoError(t, m.Steps(-1), "down 011 must not touch login_events")
|
||||
require.True(t, loginEventsExists(t), "011 down leaves login_events intact")
|
||||
|
||||
require.NoError(t, m.Steps(-1), "down 010 must drop login_events")
|
||||
require.False(t, loginEventsExists(t), "login_events must be gone after the down migration")
|
||||
|
||||
require.NoError(t, m.Steps(1), "up one migration must recreate login_events")
|
||||
require.NoError(t, m.Steps(2), "up must recreate 010 then re-apply 011")
|
||||
require.True(t, loginEventsExists(t), "login_events must be restored after the up migration")
|
||||
}
|
||||
|
||||
// autoSummarizeDefault reads the users.auto_summarize column default as text
|
||||
// ("true"/"false"), so the migration's default flip is verifiable directly.
|
||||
func autoSummarizeDefault(t *testing.T) string {
|
||||
t.Helper()
|
||||
var def string
|
||||
require.NoError(t, rawPool(t).QueryRow(context.Background(),
|
||||
`SELECT column_default FROM information_schema.columns
|
||||
WHERE table_name = 'users' AND column_name = 'auto_summarize'`).Scan(&def))
|
||||
return def
|
||||
}
|
||||
|
||||
// TestMigration011AutoSummarizeDefaultUpDown proves migration 011 is reversible:
|
||||
// up sets the auto_summarize column default to TRUE (ADR-018), down restores
|
||||
// FALSE. The down intentionally does not revert existing rows — only the default.
|
||||
func TestMigration011AutoSummarizeDefaultUpDown(t *testing.T) {
|
||||
newStore(t) // latest (011 applied)
|
||||
require.Equal(t, "true", autoSummarizeDefault(t), "011 sets the default to TRUE")
|
||||
|
||||
m := fileMigrator(t)
|
||||
require.NoError(t, m.Steps(-1), "down 011 reverts the column default")
|
||||
require.Equal(t, "false", autoSummarizeDefault(t), "default is FALSE after the down migration")
|
||||
|
||||
require.NoError(t, m.Steps(1), "up 011 re-applies the TRUE default")
|
||||
require.Equal(t, "true", autoSummarizeDefault(t))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user