# Ошибка миграции в 'rename\_discourse\_rewind\_disabled\_to\_enabled'

**URL:** https://meta.discourse.org/t/migration-error-in-rename-discourse-rewind-disabled-to-enabled/393049
**Category:** Self-hosting
**Created:** [08.Январь.2026 16:28:20 UTC](https://meta.discourse.org/t/migration-error-in-rename-discourse-rewind-disabled-to-enabled/393049 "2026-01-08T16:28:20Z")
**Posts on this page:** 1
**Showing post:** 24

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [10.Январь.2026 20:59:17 UTC](https://meta.discourse.org/t/migration-error-in-rename-discourse-rewind-disabled-to-enabled/393049/24 "2026-01-10T20:59:17Z")

</div>

Спасибо за выполнение этих запросов, @Don — вы подтвердили первопричину 🙌

Ваши результаты точно подтверждают наши предположения:

1. У вас есть схема `backup` с копией таблицы `user_options`.
2. В этой таблице всё ещё установлено старое значение по умолчанию (`column_default = false`).
3. Строка из схемы `backup` появилась в результатах запроса **раньше** , чем строка из `public`.

Когда миграция удалила значение по умолчанию для `public.user_options`, она не затронула `backup.user_options`. Затем функция `mark_readonly` запросила `information_schema.columns` без фильтрации по схеме, первой получила строку из `backup` (где значение по умолчанию всё ещё было установлено) и завершилась с ошибкой 💥

Исправление простое: достаточно добавить условие `table_schema = 'public'` в запрос, чтобы проверять только схему, с которой фактически работают миграции.

> <https://github.com/discourse/discourse/commit/2623d7a6078a62c33658ddb3b536d08d7a26cd4a>
>
> \## Problem
> 
> \`Migration::ColumnDropper.mark\_readonly\` could incorrectly detect a …default value from a non-public schema table.
> 
> The query checking for column defaults did not filter by \`table\_schema\`:
> 
> \`\`\`sql
> SELECT column\_default IS NOT NULL
> FROM information\_schema.columns
> WHERE table\_name = :table\_name
> AND column\_name = :column\_name
> \`\`\`
> 
> When multiple schemas contain tables with the same name (e.g., from backup/restore operations), this query returns multiple rows. The code uses \`.first\`, making behavior dependent on PostgreSQL's row ordering.
> 
> \## Root Cause
> 
> Don's diagnostic queries on an affected instance confirmed the issue:
> 
> \`\`\`plain
> table\_schema | column\_name | column\_default
> \--------------+---------------------------+----------------
> backup | discourse\_rewind\_disabled | false ← returned first
> public | discourse\_rewind\_disabled | false
> \`\`\`
> 
> The \`backup\` schema (from a previous \`pg\_dump\`) contained a copy of \`user\_options\` with the old default. PostgreSQL returned this row first, causing \`mark\_readonly\` to fail with "You must drop a column's default value before marking it as readonly".
> 
> \## Fix
> 
> Just a oneline -\> adding \`table\_schema = 'public'\` to the \`WHERE\` clause to ensure only the \`public\` schema is considered.
> 
> \## Why it couldn't be reproduced locally?
> 
> \- Fresh dev databases don't have \`backup\` schemas
> \- CI environments use clean databases
> \- Row ordering depends on database history (OIDs, backup/restore cycles)
> 
> Ref - https://meta.discourse.org/t/393049

---

_[View the full topic](https://meta.discourse.org/t/migration-error-in-rename-discourse-rewind-disabled-to-enabled/393049)._
