0

我需要为每个帐户配置文件存储帐户设置。我决定为此使用 SQL DB,但不确定是否应该使用复杂数据(json/xml)。

我找到了答案

在 SQL Server 数据库中使用单行配置表。馊主意?

https://softwareengineering.stackexchange.com/questions/163606/configuration-data-single-row-table-vs-name-value-pair-table

但他们都没有讨论使用包含复杂数据的单行方法

复杂数据将存储在以下数据库表中

AccountID int
AccountSettings nvarchar(max)

并将包含 AccountSettings 数据,例如

"settings": {
  "branding": {
    "header_color": "1A00C3",
    "page_background_color": "333333",
    "tab_background_color": "3915A2",
    "text_color": "FFFFFF",
    "header_logo_url": "/path/to/header_logo.png",
    "favicon_url": "/path/to/favicon.png",
  },
  "apps": {
    "use":            true,
    "create_private": false,
    "create_public":  true
  },
  "tickets": {
    "comments_public_by_default":     true,
    "list_newest_comments_first":     true,
    "collaboration":                  true,
    "private_attachments":            true,
    "agent_collision":                true
    "list_empty_views":               true,
    "maximum_personal_views_to_list": 12,
    "tagging":                        true,
    "markdown_ticket_comments":       false
  },
  "chat": {
    "maximum_request_count": 5,
    "welcome_message":       "Hello, how may I help you?",
    "enabled":               true
  },
  "voice": {
    "enabled":     true,
    "maintenance": false,
    "logging":     true
  },
  "twitter": {
    "shorten_url": "optional"
  },
  "users": {
    "tagging": true,
    "time_zone_selection": true,
    "language_selection": true
  },
  "billing": {
    "backend": 'internal'
  },
  "brands": {
    "default_brand_id": 47
  },
  "active_features": {
    "on_hold_status":                true,
    "user_tagging":                  true,
    "ticket_tagging":                true,
    "topic_suggestion":              true,
    "voice":                         true,
    "business_hours":                true,
    "facebook_login":                true,
    "google_login":                  true,
    "twitter_login":                 true,
    "forum_analytics":               true,
    "agent_forwarding":              true,
    "chat":                          true,
    "chat_about_my_ticket":          true,
    "customer_satisfaction":         true,
    "csat_reason_code":              true,
    "screencasts":                   true,
    "markdown":                      true,
    "language_detection":            true,
    "bcc_archiving":                 true,
    "allow_ccs":                     true,
    "advanced_analytics":            true,
    "sandbox":                       true,
    "suspended_ticket_notification": true,
    "twitter":                       true,
    "facebook":                      true,
    "feedback_tabs":                 true,
    "dynamic_contents":              true,
    "light_agents":                  true
  },
  "ticket_sharing_partners": [
    "foo@example.com"
  ]
}

其他解决方案是广泛使用的单行方法,例如 AccountID int SettingsName nvarchar(max) SettingsValue nvarchar(max)

可以保存数据,例如

AccountID     SettingsName                   SettingsValue
1             Branding.Header_Color          1A00C3
1             Branding.Page_Background_Color 333333
1             Apps.Use                       true

……

我假设这两种解决方案都是有效的,并且取决于应用程序的需求,但真的很想知道在使用具有单行方法的复杂数据来存储应用程序设置时是否存在我没​​有看到的问题?

4

1 回答 1

0

一个问题是,如果您有一个繁忙的大型数据库,则无法对 XML、文本、varchar(max) 类型字段进行在线重新索引(如果您有企业版)。这给 2008 R2 带来了悲痛。较新版本的 MS SQL Server 可以重新索引在线 varchar(max) 字段,因此这取决于您正在运行的版本。

此外,如果您需要搜索特定记录,您将无法查询或索引,除非您使用我经常使用的 SettingsName、SettingsValue 类型的表。这解决了重新索引在线问题(如果这适用于您的情况),以及索引字段以进行快速查询。

于 2016-02-27T21:11:52.360 回答