---
detect_relations: true

ClientContext:
  tableName: client_contexts
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
      unsigned: true
    name: string(64)

ClientContextSetting:
  tableName: client_context_settings
  columns:
    context_id: &IDREF
      type: integer
      unsigned: true
      primary: true
    name:
      type: string(128)
      notnull: true
      primary: true
    value: string
  relations:
    ClientContext:
      local: context_id
      alias: Contexts
      foreignAlias: Settings
      onUpdate: cascade
      onDelete: cascade

ClientContextUser:
  tableName: client_context_users
  columns:
    context_id: *IDREF
    user_id: *IDREF
    consumer_name:
      type: string(64)
      primary: true
  relations:
    User:
      local: user_id
      class: User
      alias: User
      foreignAlias: ClientContexts
      onUpdate: cascade
      onDelete: cascade
    ClientContext:
      local: context_id
      alias: Context
      foreignAlias: UserContexts
      onUpdate: cascade
      onDelete: cascade

ClientContextTree:
  tableName: client_context_trees
  columns:
    context_id: *IDREF
    tree_id: *IDREF
    position_hint: string(32)
  relations:
    ClientContext:
      local: context_id
      alias: Context
      foreignAlias: Trees
      onUpdate: cascade
      onDelete: cascade
    Tree:
      type: one
      local: tree_id
      alias: Tree
      foreignAlias: ClientContextTrees
      onUpdate: cascade
      onDelete: cascade
