TSUGI Framework Data Model

Slides:



Advertisements
Similar presentations
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Advertisements

2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Advanced SQL Charles Severance
Introduction to Structured Query Language (SQL)
INTRODUCTION The Group WEB BROWSER FOR RELATION Goals.
Relational Database Design and MySQL
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Oracle Data Definition Language (DDL)
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
© Copyright 2009 IMS Global Learning Consortium All Rights Reserved. 1 Charles Severance, PhD. Affiliate Coordinator IMS Global Learning Consortium (IMS.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
 Empowers to your customer  Product Rating and its Management in Ecommerce Framework  Product Reviews and Management: Collecting customer opinion about.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Relational Database Design and MySQL Charles Severance
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Using Workflow With Dataforms Tim Borntreger, Director of Client Services.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
1 Copyright © 2005, Oracle. All rights reserved. Oracle Database Administration: Overview.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Understanding Core Database Concepts Lesson 1. Objectives.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
ASP.NET Programming with C# and SQL Server First Edition
INTRODUCTION TO DATABASES (MICROSOFT ACCESS)
Y.-H. Chen International College Ming-Chuan University Fall, 2004
IMS Basic Learning Tools Interoperability (Basic LTI)
Databases.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CS320 Web and Internet Programming SQL and MySQL
Advanced SQL Charles Severance
The Basics of Data Manipulation
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to MySQL.
Database Keys and Constraints
Session 4 PHP & MySQL.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
Teaching slides Chapter 8.
SQL DATA CONSTRAINTS.
Oracle Data Definition Language (DDL)
MIS2502: Data Analytics SQL – Putting Information Into a Database
CS122 Using Relational Databases and SQL
Contents Preface I Introduction Lesson Objectives I-2
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
Data Definition Language
Charles Severance Single Table SQL.
CS3220 Web and Internet Programming SQL and MySQL
Understanding Core Database Concepts
CS122 Using Relational Databases and SQL
Presentation transcript:

TSUGI Framework Data Model Charles Severance www.tsugi.org

YouTube Channel http://youtube.tsugi.org/

MySQL WorkBench A free tool from Oracle / MySQL Database design, visualization, etc... http://www.mysql.com/products/workbench/design/

The Primary Objects in Tsugi $USER – The current Logged in user $CONTEXT – A more general word for "course" – could also mean "worksite" $LINK – Which "resource link" within the context are we "in" at this moment Tennant – Tsugi can serve learning tools to multiple tenants and keep the data separate http://do1.dr-chuck.com/tsugi/phpdoc/classes/Tsugi.Core.Context.html

Tenant Context User Link (Many)

Tenant Context User Link (Many)

tsugi/docs/lectures/02-Data-Model-Workbench.mwb

Conventions (Rails like) All rows have auto-increment integer primary key Date fields "..._at" Foreign key names "table_id"

Not 100% Rails-Like Primary key names "table_id" Column and table names are both singular

Sha256 Key Conventions Logical keys like user_id coming from the LMS can be long (>4096) We model these as TEXT to avoid length limitations We SHA256 these and index/unique the SHA256 column

ON DELETE Convention We expect this to be a multi-tenant container Tenants may come and go We want to be able to do the "transitive closure" of a tenant We want to be able to delete a tenant and all associated data in a single command.

ON DELETE for Tool Tables Every table that is created for tool data must connect to one or more of these tables with an ON DELETE CASCADE clause lti_link lti_context lti_user lti_key

tsugi/mod/attend/database.php create table {$CFG->dbprefix}attend ( link_id INTEGER NOT NULL, user_id INTEGER NOT NULL, attend DATE NOT NULL, ipaddr VARCHAR(64), updated_at DATETIME NOT NULL, CONSTRAINT `{$CFG->dbprefix}attend_ibfk_1` FOREIGN KEY (`link_id`) REFERENCES `{$CFG->dbprefix}lti_link` (`link_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `{$CFG->dbprefix}attend_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `{$CFG->dbprefix}lti_user` (`user_id`) UNIQUE(link_id, user_id, attend) ) ENGINE = InnoDB DEFAULT CHARSET=utf8

IMS Learning Tools Interoperability (LTI) Launch Quick Review...

LTI Launch When the user clicks a link in the LMS The tool is launched using LTI/OAuth May be a new window or in an iframe LMS data is signed using a shared secret and and passed to the external tool The tool provisions the context, user, and link and then sets up a session automatically logging the user into the tool http://developers.imsglobal.org/

LTI Sample Launch Data lti_version=LTI-1p0 lti_message_type=basic-lti-launch-request context_id=456434513 context_title=SI301 – PHP resource_link_id=120988f929-274612 user_id=292832126 roles=Instructor lis_person_name_full=Charles R. Severance lis_person_contact_email_primary = csev@umich.edu tool_consumer_instance_description=University of School oauth_consumer_key=lmsng.school.edu ...

LMS Looks up User and Course Information in LMS session. LMS (LTI Consumer) LMS Looks up User and Course Information in LMS session. Information is signed using OAuth using a shared secret Week 1 Local Resource LTI Tool Movie Form data sent to Browser Tool (LTI Provider)

Tool looks up secret and validates signature. LMS (LTI Consumer) Form is immediately auto-submitted using JavaScript. <form action=”tool”/> <input name=”user_id” value=”2348d8dd” /> <input name=”oauth_token” value=”abc.edu” /> </form> Tool (LTI Provider) Tool looks up secret and validates signature. Tool provisions user, course, and session. Tool sends redirect

Tool produces first page. LMS (LTI Consumer) Browser follows redirect… <head> <meta redirect page=”main.php”> </head> Tool (LTI Provider) Tool produces first page.

LMS (LTI Consumer) Tool (LTI Provider)

LTI Launch and the Core Tables a.k.a. "The big join"

Tool looks up secret and validates signature. LMS (LTI Consumer) <form action=”tool”/> <input name=”user_id” value=”2348d8dd” /> <input name=”oauth_token” value=”abc.edu” /> </form> Tool (LTI Provider) Tool looks up secret and validates signature. Tool provisions user, course, and session. Tool sends redirect

tsugi/docs/lectures/02-Data-Model-Workbench.mwb

Problems to Solve Might be seeing context, link and user for the first time – need to create Might already have records in place but see new data like name, title or email Might already have the data no changed are needed (most common) Need to provision the session and global objects ($USER, $CONTEXT, and $LINK)

SELECT k. key_id, k. key_key, k. secret, k. new_secret, c SELECT k.key_id, k.key_key, k.secret, k.new_secret, c.settings_url AS key_settings_url, n.nonce, c.context_id, c.title AS context_title, context_sha256, c.settings_url AS context_settings_url, l.link_id, l.title AS link_title, l.settings AS link_settings, l.settings_url AS link_settings_url, u.user_id, u.displayname AS user_displayname, u.email AS user_email, u.subscribe AS subscribe, u.user_sha256 AS user_sha256, m.membership_id, m.role, m.role_override, p.profile_id, p.displayname AS profile_displayname, p.email AS profile_email, p.subscribe AS profile_subscribe, s.service_id, s.service_key AS service, r.result_id, r.sourcedid, r.grade, r.result_url FROM lti_key AS k LEFT JOIN lti_nonce AS n ON k.key_id = n.key_id AND n.nonce = :nonce LEFT JOIN lti_context AS c ON k.key_id = c.key_id AND c.context_sha256 = :context LEFT JOIN lti_link AS l ON c.context_id = l.context_id AND l.link_sha256 = :link LEFT JOIN lti_user AS u ON k.key_id = u.key_id AND u.user_sha256 = :user LEFT JOIN lti_membership AS m ON u.user_id = m.user_id AND c.context_id = m.context_id LEFT JOIN profile AS p ON u.profile_id = p.profile_id LEFT JOIN lti_service AS s ON k.key_id = s.key_id AND s.service_sha256 = :service LEFT JOIN lti_result AS r ON u.user_id = r.user_id AND l.link_id = r.link_id WHERE k.key_sha256 = :key LIMIT 1 tsugi/lib/vendor/Tsugi/Core/LTIX.php loadAllData()

After the "Big Join" The join may be Completely empty (all new data) Match launch data perfectly Partially there or updated data LTIX::adjustData() uses INSERT and UPDATE statements to make sure the data in the lti_ tables matches incoming LTI data Session is provisioned and tool is launched tsugi/lib/vendor/Tsugi/Core/LTIX.php

A blend of Moodle and Rails Migrations A blend of Moodle and Rails

Creating and Updating Schema We want completely automated schema upgrades like Moodle and Rails Should be convenient for both new installations and continuous evolution during development Each table has a version number based on date/time that the change was made 201409242100

Global Database Version The global database version should be the maximum version across all database.php files It is stored in setup.php Used to remind folks when to run upgrade.php <?php // This is where we change the overall database version to trigger // upgrade checking - don't change this unless you want to trigger // database upgrade messages it should be the max of all versions in // all database.php files. $CFG->dbversion = 201410150800;

Goes through all of the database Goes through all of the database.php files below the $CFG->tool_folders and checks for any needed new tables and/or tables to upgrade.

Structure of a database.php $DATABASE_UNINSTALL Array of statements to drop all tables for the tool $DATABASE_INSTALL Array of table names and CREATE statements $DATABASE_UPGRADE(optional) A function which is given the "old version" and returns the "new version" after patching the table appropriately

tsugi/mod/attend/database.php <?php // The SQL to uninstall this tool $DATABASE_UNINSTALL = array( "drop table if exists {$CFG->dbprefix}attend" ); // The SQL to create the tables if they don't exist $DATABASE_INSTALL = array( array( "{$CFG->dbprefix}attend", "create table {$CFG->dbprefix}attend ( link_id INTEGER NOT NULL, user_id INTEGER NOT NULL, ... CONSTRAINT `{$CFG->dbprefix}attend_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `{$CFG->dbprefix}lti_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, UNIQUE(link_id, user_id, attend) ) ENGINE = InnoDB DEFAULT CHARSET=utf8") tsugi/mod/attend/database.php

tsugi/mod/peer-grade/database.php // Database upgrade $DATABASE_UPGRADE = function($oldversion) { global $CFG; // Version 2014042200 improvements if ( $oldversion < 2014042200 ) { $sql= "ALTER TABLE {$CFG->dbprefix}peer_submit ADD regrade TINYINT NULL"; echo("Upgrading: ".$sql."<br/>\n"); error_log("Upgrading: ".$sql); $q = $PDOX->queryDie($sql); } return 2014042200; }; // Don't forget the semicolon on anonymous functions :) tsugi/mod/peer-grade/database.php

... array( "{$CFG->dbprefix}peer_submit", "create table {$CFG->dbprefix}peer_submit ( submit_id INTEGER NOT NULL KEY AUTO_INCREMENT, assn_id INTEGER NOT NULL, user_id INTEGER NOT NULL, json TEXT NULL, note TEXT NULL, reflect TEXT NULL, regrade TINYINT NULL, updated_at DATETIME NOT NULL, created_at DATETIME NOT NULL, .... At the same time you add the migration to $DATABASE_UPGRADE, you change the schema in $DATABASE_INSTALL. The upgrade will be called with a "later" version for fresh installs. tsugi/mod/peer-grade/database.php

Summary Database structure for the core LTI launch data Column and table naming rules Sha256 key convention Rules for tool tables LTI Launch Review Handling launch data with the "Big Join" Tool table creation and migration