<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="local/treestudyplan/db" VERSION="20240415" COMMENT="XMLDB file for Moodle local/treestudyplan"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
  <TABLES>
    <TABLE NAME="local_treestudyplan_invit" COMMENT="Invitations to view report card">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="ID of user to view report of"/>
        <FIELD NAME="name" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Name or description of invite recipient"/>
        <FIELD NAME="email" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="email address the invite was sent to"/>
        <FIELD NAME="invitekey" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Invitation key for this invite"/>
        <FIELD NAME="idate" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false" COMMENT="Date the invite was created"/>
        <FIELD NAME="unlockdate" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false" COMMENT="Unlock date for mandatory study plans"/>
        <FIELD NAME="identifier" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Freeform identifier field for integration purposes"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="user_id-id" TYPE="foreign" FIELDS="user_id" REFTABLE="user" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="name" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="shortname" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
        <FIELD NAME="idnumber" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="aggregation" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="bistate" SEQUENCE="false"/>
        <FIELD NAME="aggregation_config" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="context_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="csync_flag" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Flags the studyplan as needing a csync update"/>
        <FIELD NAME="suspended" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
        <FIELD NAME="template" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_user" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="user_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="studyplan_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="user_id-id" TYPE="foreign" FIELDS="user_id" REFTABLE="user" REFFIELDS="id"/>
        <KEY NAME="studyplan_id-id" TYPE="foreign" FIELDS="studyplan_id" REFTABLE="local_treestudyplan" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_cohort" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="studyplan_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="cohort_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_line" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="page_id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="name" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="color" TYPE="char" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="sequence" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="enrollable" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Let's student enroll in a study plan line, only after which the line is active for this user."/>
        <FIELD NAME="enrolrole" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Roles allowed to enrol a student in this course (in the studyplan context)"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="page_id-id" TYPE="foreign" FIELDS="page_id" REFTABLE="local_treestudyplan_page" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_item" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="line_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="type" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="conditions" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="slot" TYPE="int" LENGTH="9" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="layer" TYPE="int" LENGTH="9" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="competency_id" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="badge_id" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="course_id" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="continuation_id" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="span" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="competency_id-id" TYPE="foreign" FIELDS="competency_id" REFTABLE="competency" REFFIELDS="id"/>
        <KEY NAME="badge_id-id" TYPE="foreign" FIELDS="badge_id" REFTABLE="badge" REFFIELDS="id"/>
        <KEY NAME="course_id-id" TYPE="foreign" FIELDS="course_id" REFTABLE="course" REFFIELDS="id"/>
        <KEY NAME="line_id-id" TYPE="foreign" FIELDS="line_id" REFTABLE="local_treestudyplan_line" REFFIELDS="id"/>
        <KEY NAME="continuation_id-id" TYPE="foreign" FIELDS="continuation_id" REFTABLE="local_treestudyplan_item" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_connect" COMMENT="Table">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="from_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="to_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="from_id-id" TYPE="foreign" FIELDS="from_id" REFTABLE="local_treestudyplan_item" REFFIELDS="id"/>
        <KEY NAME="to_id-id" TYPE="foreign" FIELDS="to_id" REFTABLE="local_treestudyplan_item" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_gradeinc" COMMENT="Information about whether or not to include grade_items as goals">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="grade_item_id" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="include" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
        <FIELD NAME="studyitem_id" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="required" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="grade_item_id-id" TYPE="foreign" FIELDS="grade_item_id" REFTABLE="grade_item" REFFIELDS="id"/>
        <KEY NAME="studyitem_id-id" TYPE="foreign" FIELDS="studyitem_id" REFTABLE="local_treestudyplan_item" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_gradecfg" COMMENT="Stores grade configuration for scales et al.">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="scale_id" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="grade_points" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="min_completed" TYPE="number" LENGTH="20" NOTNULL="false" SEQUENCE="false" DECIMALS="1"/>
        <FIELD NAME="min_progress" TYPE="number" LENGTH="20" NOTNULL="false" SEQUENCE="false" DECIMALS="1"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="scale_id-id" TYPE="foreign" FIELDS="scale_id" REFTABLE="scale" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_teachers" COMMENT="Caches the links between teachers and studyplans">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="teacher_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="studyplan_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="update_time" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_period" COMMENT="Stores timing information about the different periods in a study plan page">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="page_id" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="period" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="startdate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="enddate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="fullname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="page_id-id" TYPE="foreign" FIELDS="page_id" REFTABLE="local_treestudyplan_page" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_page" COMMENT="Single page in a studyplan">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="studyplan_id" TYPE="int" LENGTH="20" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
        <FIELD NAME="periods" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
        <FIELD NAME="fullname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
        <FIELD NAME="startdate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="enddate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_lineuser" COMMENT="Default comment for the table, please edit me">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="line_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="user_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="timeenrolled" TYPE="int" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
        <FIELD NAME="enrolled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
        <FIELD NAME="enrolledby" TYPE="int" LENGTH="18" NOTNULL="false" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="line_id-id" TYPE="foreign" FIELDS="line_id" REFTABLE="local_treestudyplan_line" REFFIELDS="id"/>
        <KEY NAME="user_id-id" TYPE="foreign" FIELDS="user_id" REFTABLE="user" REFFIELDS="id"/>
        <KEY NAME="enrolledby-id" TYPE="foreign" FIELDS="enrolledby" REFTABLE="user" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="local_treestudyplan_coach" COMMENT="Default comment for the table, please edit me">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="user_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
        <FIELD NAME="studyplan_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="user_id-id" TYPE="foreign" FIELDS="user_id" REFTABLE="user" REFFIELDS="id"/>
        <KEY NAME="studyplan_id-id" TYPE="foreign" FIELDS="studyplan_id" REFTABLE="local_treestudyplan" REFFIELDS="id"/>
      </KEYS>
    </TABLE>
  </TABLES>
</XMLDB>
