- 400 → 422 для всех ошибок валидации входных данных (handlers: export, quote, sync, vendor_spec, partnumber_books, pricelist) - SQL-запросы вынесены из handlers в localdb (partnumber_books, pricelist, support_bundle); ValidateMariaDBConnection перенесён в internal/db/validate.go - List-ответы унифицированы: ключ items, поля total_count/page/per_page/total_pages (component, pricelist, partnumber_books); шаблоны обновлены - Молчаливые ошибки заменены на slog.Warn/Error (support_bundle, vendor_spec, component, configuration, local_configuration, localdb) - N+1 запросы устранены: batch-запросы в export.go и vendor_workspace_import.go - fmt.Println → slog в cmd/ (qfs, migrate, migrate_ops_projects, migrate_project_updated_at) - Заголовки recovery/verify добавлены во все 28 SQL-миграций - Добавлены bible-local/runtime-flows.md и bible-local/decisions/ - Обновлён субмодуль bible до v0.2.0-13 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.5 KiB
SQL
44 lines
1.5 KiB
SQL
-- Tables affected: qt_configurations
|
|
-- recovery.not-started: check first; ADD COLUMN fails if pricelist_id already exists
|
|
-- recovery.partial: ALTER TABLE qt_configurations DROP COLUMN pricelist_id;
|
|
-- recovery.completed: no action needed
|
|
-- verify: pricelist_id column missing | SELECT 1 FROM information_schema.COLUMNS WHERE table_schema=DATABASE() AND table_name='qt_configurations' AND column_name='pricelist_id' HAVING COUNT(*)=0
|
|
|
|
-- Add pricelist binding to configurations
|
|
ALTER TABLE qt_configurations
|
|
ADD COLUMN pricelist_id BIGINT UNSIGNED NULL AFTER server_count;
|
|
|
|
ALTER TABLE qt_configurations
|
|
ADD INDEX idx_qt_configurations_pricelist_id (pricelist_id),
|
|
ADD CONSTRAINT fk_qt_configurations_pricelist_id
|
|
FOREIGN KEY (pricelist_id)
|
|
REFERENCES qt_pricelists(id)
|
|
ON DELETE RESTRICT
|
|
ON UPDATE CASCADE;
|
|
|
|
-- Backfill existing configurations to latest active pricelist
|
|
SET @latest_active_pricelist_id := (
|
|
SELECT id
|
|
FROM qt_pricelists
|
|
WHERE is_active = 1
|
|
ORDER BY created_at DESC
|
|
LIMIT 1
|
|
);
|
|
|
|
UPDATE qt_configurations
|
|
SET pricelist_id = @latest_active_pricelist_id
|
|
WHERE pricelist_id IS NULL
|
|
AND @latest_active_pricelist_id IS NOT NULL;
|
|
|
|
-- Recalculate usage_count from configuration bindings
|
|
UPDATE qt_pricelists SET usage_count = 0;
|
|
|
|
UPDATE qt_pricelists pl
|
|
JOIN (
|
|
SELECT pricelist_id, COUNT(*) AS cnt
|
|
FROM qt_configurations
|
|
WHERE pricelist_id IS NOT NULL
|
|
GROUP BY pricelist_id
|
|
) cfg ON cfg.pricelist_id = pl.id
|
|
SET pl.usage_count = cfg.cnt;
|