MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / init_default_settings

Function init_default_settings

src/config/settings.py:668–707  ·  view source on GitHub ↗

初始化数据库中的默认设置 如果设置项不存在,则创建并设置默认值

()

Source from the content-addressed store, hash-verified

666
667
668def init_default_settings() -> None:
669 """
670 初始化数据库中的默认设置
671 如果设置项不存在,则创建并设置默认值
672 """
673 try:
674 from ..database.session import get_db
675 from ..database.crud import get_setting, set_setting
676
677 with get_db() as db:
678 for attr_name, defn in SETTING_DEFINITIONS.items():
679 existing = get_setting(db, defn.db_key)
680 if not existing:
681 default_value = defn.default_value
682 if attr_name == "database_url":
683 env_url = os.environ.get("APP_DATABASE_URL") or os.environ.get("DATABASE_URL")
684 if env_url:
685 default_value = _normalize_database_url(env_url)
686 default_value = _value_to_string(default_value)
687 set_setting(
688 db,
689 defn.db_key,
690 default_value,
691 category=defn.category.value,
692 description=defn.description
693 )
694 print(f"[Settings] 初始化默认设置: {defn.db_key} = {default_value if not defn.is_secret else '***'}")
695 elif attr_name == "log_retention_days" and str(existing.value or "").strip() == "30":
696 upgraded_value = _value_to_string(defn.default_value)
697 set_setting(
698 db,
699 defn.db_key,
700 upgraded_value,
701 category=defn.category.value,
702 description=defn.description
703 )
704 print(f"[Settings] 升级默认设置: {defn.db_key} 30 -> {upgraded_value}")
705 except Exception as e:
706 if "未初始化" not in str(e):
707 print(f"[Settings] 初始化默认设置失败: {e}")
708
709
710def _load_settings_from_db() -> Dict[str, Any]:

Callers 3

initialize_databaseFunction · 0.85
reset_databaseFunction · 0.85
get_settingsFunction · 0.85

Calls 6

get_dbFunction · 0.85
get_settingFunction · 0.85
_normalize_database_urlFunction · 0.85
_value_to_stringFunction · 0.85
set_settingFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected