visionA/visionA-backend/migrations/0006_model_sharing.down.sql
jim800121chen 47a1d4d0ef feat(backend): 設備註冊 + 模型共享 backend(B 設備管理 + C 模型共享)
B 設備管理(feature-device-mgmt-tdd):
- POST /api/devices/:id/register + /unregister(owner 檢查 + representative 擋
  + 已註冊擋 + SetRegistered 單欄翻轉,不碰 unpair 軟刪)
- error codes ALREADY_REGISTERED / REPRESENTATIVE_DEVICE(409)
- 不需 migration(registered_at 欄/index/讀寫已在 0005)

C 模型共享(feature-model-sharing-tdd,security 深審 APPROVE):
- migration 0006:models.visibility enum DEFAULT 'private'(零行為改變)+ model_shares 表
- canAccessModel single source(owner ∪ share ∪ public ∪ tenant):profile + download 共用
- GET /library(cursor keyset)/ GET /:id/profile(404 防列舉、GetWithOwner join name 不洩 email)
  / PATCH /:id/visibility(owner-only)/ shares CRUD / download 放寬
- tenant 因 OIDC 無 org claim 留 stub(恆空、安全預設;補 org claim 需重送 security 深審)

reviewer 通過(B 三條紅線 / C security APPROVE 無 C/M)。130 dbtest 全綠、gosec 新檔 0。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-02 16:29:50 +08:00

18 lines
821 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 0006_model_sharing.down.sql
--
-- 反向 0006對稱移除 model_shares 表、models.visibility 欄與相關 index / constraint。
-- 順序:先刪依賴 visibility 的 partial index → 刪 model_shares 表(其 index 隨表 DROP 自動移除)
-- → 刪 models 的 constraint + 欄位。
-- (3) 共享庫查詢 index。
DROP INDEX IF EXISTS idx_models_public_active;
-- (2) model_shares 表idx_model_shares_grantee 隨表 DROP 自動移除)。
DROP TABLE IF EXISTS model_shares;
-- (1) models.visibility 欄與其 CHECK constraint。
-- 先 DROP CONSTRAINT 再 DROP COLUMNDROP COLUMN 也會連帶移除 constraint
-- 此處顯式先移以求對稱清楚)。
ALTER TABLE models DROP CONSTRAINT IF EXISTS chk_models_visibility;
ALTER TABLE models DROP COLUMN IF EXISTS visibility;