SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Constructing SQL Queries
for AtoM
Constructing SQL Queries
for AtoM
An overview of AtoM's data model and start constructing simple queries for
reporting and data cleanup, among other uses, using MySQL Workbench.
Outline
Utilities to ease working with MySQL
Data model overview and resources
Explore the schema using SQL queries
Practical examples
MySQL Client
Utilities
MySQL command line interface
● Req command line access
MySQL Workbench
● Runs locally
● Network connection to db
PHPMyAdmin
● Web delivered
● Requires installation on server
Sequel Pro (for macOS)
Today I’ll be using MySQL Workbench
● Windows, macOS (OS X), Linux clients
● Don’t really want to install anything directly on Vagrant
box as I purge it frequently
MySQL
Workbench
Installing for use with AtoM Vagrant box
● Download from:
○ https://www.mysql.com/products/workbench/
○ ...and run the installer
● Grant access to a user to connect to mysql from host
machine
○ mysql -u root -h localhost -p
○ GRANT ALL ON *.* to root@'10.10.10.1'
IDENTIFIED BY 'root';
○ FLUSH PRIVILEGES;
● Launch MySQL Workbench
○ Connect to 10.10.10.10
○ User: root
○ Pw: root
AtoM’s ERD
We are going to focus on a few specific tables
https://wiki.accesstomemory.org/Development/ERDs
Entity Model
https://www.accesstomemory.org/en/docs/2.3/user-manual/overview/entity-types/
Let’s look at an Archival description in AtoM:
● Fred Wah Fonds
● Examine the URL:
● http://10.10.10.10/fred-wah-fonds
● Slug is “fred-wah-fonds”
SELECT * FROM slug WHERE slug.slug = "fred-wah-fonds";
We can browse all the slugs in this table:
● SELECT * FROM slug;
Use slug.object_id to find the description:
SELECT * FROM information_object WHERE id = 54206;
Examine an
Archival
Description
Tables:
● slug
● information_object
Object Table
A short diversion...
Recalling the ORM discussion earlier:
● Most models extend ‘object’ model
● Object table row represented by object class/model
● Id’s for extended classes are derived from object class
● Ensures id’s are unique across different object types
● SELECT * FROM object;
● Note: class_name, id
SELECT * FROM slug
INNER JOIN object ON object.id = slug.object_id
INNER JOIN information_object ON information_object.id = object.id
WHERE slug.slug = "fred-wah-fonds";
Or drop the join on object entirely:
SELECT * FROM slug
INNER JOIN information_object ON information_object.id = slug.object_id
WHERE slug.slug = "fred-wah-fonds";
More about
Information
Objects
Aka Archival Descriptions
I18n
Culture and translations
The i18n tables contain translated strings
● 1 to many relationship between a table and i18n equivalent
● If a translation record is not available for chosen culture
○ Display strings from default culture i18n record
● If a translation record is available for chosen culture
○ Strings will be populated from this record based on selected culture
○ If the string is null for a specific field within i18n row
■ Fall back to i18n record matching system default culture
Looking at the record for ‘fred-wah-fonds’:
SELECT * FROM slug
INNER JOIN information_object ON information_object.id = slug.object_id
INNER JOIN information_object_i18n
ON information_object_i18n.id = information_object.id
WHERE slug.slug = "fred-wah-fonds";
Look for ‘extent_and_medium’
Note values for field ‘culture’
I18n
i18n translatable string examples from
information_object_i18n
Events and
Actors
From information_object, dates are linked to creators
● Dates → event table
● Creators → actor table
Add join from information_object to event table:
SELECT * FROM slug
INNER JOIN information_object ON information_object.id = slug.object_id
INNER JOIN event ON event.object_id = information_object.id
WHERE slug.slug = "example-fonds";
Add a join to actor table:
SELECT * FROM slug
INNER JOIN information_object ON information_object.id = slug.object_id
INNER JOIN event ON event.object_id = information_object.id
INNER JOIN actor ON actor.id = event.actor_id
INNER JOIN actor_i18n ON actor_i18n.id = actor.id
WHERE slug.slug = "example-fonds";
1. Let’s add a new event (creation date) to the information object
○ A new event row is created
2. Let’s add an authority record event
○ A new event record and an associated actor record created
3. Now add an authority record without dates
○ Event and actor created, but event will have null dates
Terms
Associating terms with objects
● Cross-reference table object_term_relation
● Example-fonds has an id of 57671
SELECT * FROM object_term_relation
WHERE object_term_relation.object_id = 57671;
Join in the term table:
SELECT * FROM object_term_relation
INNER JOIN term ON term.id = object_term_relation.term_id
WHERE object_term_relation.object_id = 57671;
Add another join to the term_i18n table:
SELECT * FROM slug
INNER JOIN information_object ON information_object.id = slug.object_id
INNER JOIN object_term_relation ON object_term_relation.object_id = slug.object_id
INNER JOIN term ON term.id = object_term_relation.term_id
INNER JOIN term_i18n ON term_i18n.id = term.id
WHERE slug.slug = "example-fonds";
Object Object_term_relation Term
1:many many:1
Taxonomy
That leads us to the taxonomy table
● Each term belongs to a taxonomy
● So when we found the terms on the previous slide:
SELECT * FROM object_term_relation
INNER JOIN term ON term.id = object_term_relation.term_id
WHERE object_term_relation.object_id = 57671;
We have the taxonomy_id from the term table
Let’s add the taxonomy table with a join:
SELECT * FROM object_term_relation
INNER JOIN term ON term.id = object_term_relation.term_id
INNER JOIN taxonomy ON taxonomy.id = term.taxonomy_id
INNER JOIN taxonomy_i18n ON taxonomy_i18n.id = taxonomy.id
WHERE object_term_relation.object_id = 57671
AND taxonomy_i18n.culture = 'en';
Notes and
Properties
Both Notes and Properties have object_id as foreign key
Tying these records back to the objects is simply:
SELECT * FROM note
INNER JOIN note_i18n ON note_i18n.id = note.id
WHERE note.object_id = 57671;
Have a look at type_id → maps to terms table:
SELECT * FROM term
INNER JOIN term_i18n ON term_i18n.id = term.id
WHERE term.id = 174 AND term_i18n.culture = 'en';
Similarly for properties:
SELECT * FROM property
INNER JOIN property_i18n ON property_i18n.id = property.id
WHERE property.object_id = 57671;
Repository
Repository details are contained in both the repository and actor tables
● Repositories have some fields in common with actor
● Need both to get all details
SELECT * FROM repository
WHERE repository.id = 57203;
Add in the translatable strings:
SELECT * FROM repository
INNER JOIN repository_i18n ON repository_i18n.id = repository.id
WHERE repository.id = 57203;
Add in the fields from actor & actor_i18n:
SELECT * FROM repository
INNER JOIN repository_i18n ON repository_i18n.id = repository.id
INNER JOIN actor on actor.id = repository.id
INNER JOIN actor_i18n ON actor.id = actor_i18n.id
WHERE repository.id = 57203;
Nested Sets What are all those lft and rgt fields?
● Nested Sets!
● A way to record hierarchical relationships among similar entities
● https://en.wikipedia.org/wiki/Nested_set_model
E.g. Information objects
● These are hierarchical objects
● Levels of Description (fonds, collection, item, part, series, etc)
Let’s find a top level information_object
● Example-fonds (id: 57671, lft: 1638, rgt: 1641)
● Fred-wah-fonds (id: 54206, lft: 2, rgt: 1517)
Let’s find all objects included in this object’s hierarchy:
SELECT * FROM information_object
WHERE information_object.lft >= 1638
AND information_object.rgt <= 1641
ORDER BY information_object.lft;
Public domain image borrowed from https://en.wikipedia.org/wiki/Nested_set_model
Update Queries
Caution!
● Backups!
● Know how to restore from backups!
● Practice on a backup or offline copy
● Depending on what you’ve done, might need to:
○ Rebuild nested sets
○ Re-index
What’s next?
● Set all ‘Draft’ status objects to ‘Published’:
○ UPDATE status SET status_id=160 WHERE type_id=158;
● Find info object id when slug not known:
○ SELECT id FROM information_object_i18n WHERE title='TITLEHERE';
○ SELECT id FROM information_object_i18n WHERE title LIKE 'TITLEHE%';
● Get a count of descriptions in database:
○ SELECT COUNT(*) FROM information_object_i18n;
● Find titles containing quote characters:
○ SELECT io.title, s.slug FROM information_object_i18n io JOIN slug s ON io.id = s.object_id WHERE
io.title like '%"%';
● See all note type terms and get a count of each:
○ SELECT term.id, term_i18n.name, COUNT(note.type_id) FROM term
INNER JOIN term_i18n ON term.id = term_i18n.id
INNER JOIN note ON term.id = note.type_id
WHERE culture='en'
GROUP BY note.type_id;
See https://www.accesstomemory.org/docs/latest/admin-manual/maintenance/cli-tools/#common-atom-database-queries
SQL Join reference: http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
Q&AQ&A
www.accesstomemory.org
www.artefactual.com

Weitere ähnliche Inhalte

Was ist angesagt?

HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examplesAlfredo Torre
 
IBM Lotus Notes Clients - Differences
IBM Lotus Notes Clients - DifferencesIBM Lotus Notes Clients - Differences
IBM Lotus Notes Clients - DifferencesDvir Reznik
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to BootstrapSeble Nigussie
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Databricks
 
Change Data Feed in Delta
Change Data Feed in DeltaChange Data Feed in Delta
Change Data Feed in DeltaDatabricks
 
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Gabriele Baldassarre
 
Building a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and DockerBuilding a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and DockerWellington Marinho
 
Intro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyIntro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyAdam Soucie
 
Apache Flink and Apache Hudi.pdf
Apache Flink and Apache Hudi.pdfApache Flink and Apache Hudi.pdf
Apache Flink and Apache Hudi.pdfdogma28
 
Iceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsIceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsAlluxio, Inc.
 

Was ist angesagt? (20)

Json
JsonJson
Json
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examples
 
File Format Benchmark - Avro, JSON, ORC & Parquet
File Format Benchmark - Avro, JSON, ORC & ParquetFile Format Benchmark - Avro, JSON, ORC & Parquet
File Format Benchmark - Avro, JSON, ORC & Parquet
 
IBM Lotus Notes Clients - Differences
IBM Lotus Notes Clients - DifferencesIBM Lotus Notes Clients - Differences
IBM Lotus Notes Clients - Differences
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
Integrating Apache Spark and NiFi for Data Lakes
Integrating Apache Spark and NiFi for Data LakesIntegrating Apache Spark and NiFi for Data Lakes
Integrating Apache Spark and NiFi for Data Lakes
 
AtoM, Authenticity, and the Chain of Custody
AtoM, Authenticity, and the Chain of CustodyAtoM, Authenticity, and the Chain of Custody
AtoM, Authenticity, and the Chain of Custody
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 
Change Data Feed in Delta
Change Data Feed in DeltaChange Data Feed in Delta
Change Data Feed in Delta
 
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
 
Building a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and DockerBuilding a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and Docker
 
Intro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyIntro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS Property
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
Apache Flink and Apache Hudi.pdf
Apache Flink and Apache Hudi.pdfApache Flink and Apache Hudi.pdf
Apache Flink and Apache Hudi.pdf
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
Iceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsIceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data Analytics
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 

Ähnlich wie Constructing SQL queries for AtoM

Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nicolas Thon
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overviewpradeepkothiyal
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)Samnang Chhun
 
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfitallanh0526
 
Cool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchCool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchclintongormley
 
#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects ExplainedAtul Gupta(8X)
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationMoniruzzaman _
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationRandy Connolly
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
Bubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsBubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsStefan Urbanek
 
WEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And AttributesWEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And AttributesDataminingTools Inc
 
WEKA:Data Mining Input Concepts Instances And Attributes
WEKA:Data Mining Input Concepts Instances And AttributesWEKA:Data Mining Input Concepts Instances And Attributes
WEKA:Data Mining Input Concepts Instances And Attributesweka Content
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
Itemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integrationItemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integration{item:foo}
 

Ähnlich wie Constructing SQL queries for AtoM (20)

Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Day 2
Day 2Day 2
Day 2
 
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfit
 
Cool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchCool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearch
 
#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained
 
Creating classes and applications in java
Creating classes and applications in javaCreating classes and applications in java
Creating classes and applications in java
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Bubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsBubbles – Virtual Data Objects
Bubbles – Virtual Data Objects
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
NHibernate
NHibernateNHibernate
NHibernate
 
WEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And AttributesWEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And Attributes
 
WEKA:Data Mining Input Concepts Instances And Attributes
WEKA:Data Mining Input Concepts Instances And AttributesWEKA:Data Mining Input Concepts Instances And Attributes
WEKA:Data Mining Input Concepts Instances And Attributes
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Itemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integrationItemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integration
 
08ui.pptx
08ui.pptx08ui.pptx
08ui.pptx
 
Salesforce connect
Salesforce connectSalesforce connect
Salesforce connect
 

Mehr von Artefactual Systems - AtoM

Things I wish I'd known - AtoM tips, tricks, and gotchas
Things I wish I'd known - AtoM tips, tricks, and gotchasThings I wish I'd known - AtoM tips, tricks, and gotchas
Things I wish I'd known - AtoM tips, tricks, and gotchasArtefactual Systems - AtoM
 
Creating your own AtoM demo data set for re-use with Vagrant
Creating your own AtoM demo data set for re-use with VagrantCreating your own AtoM demo data set for re-use with Vagrant
Creating your own AtoM demo data set for re-use with VagrantArtefactual Systems - AtoM
 
Looking Ahead: AtoM's governance, development, and future
Looking Ahead: AtoM's governance, development, and futureLooking Ahead: AtoM's governance, development, and future
Looking Ahead: AtoM's governance, development, and futureArtefactual Systems - AtoM
 
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...Artefactual Systems - AtoM
 
An Introduction to AtoM, Archivematica, and Artefactual Systems
An Introduction to AtoM, Archivematica, and Artefactual SystemsAn Introduction to AtoM, Archivematica, and Artefactual Systems
An Introduction to AtoM, Archivematica, and Artefactual SystemsArtefactual Systems - AtoM
 
National Archives of Norway - AtoM and Archivematica intro workshop
National Archives of Norway - AtoM and Archivematica intro workshopNational Archives of Norway - AtoM and Archivematica intro workshop
National Archives of Norway - AtoM and Archivematica intro workshopArtefactual Systems - AtoM
 
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...Artefactual Systems - AtoM
 
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...Artefactual Systems - AtoM
 
Digital Curation using Archivematica and AtoM: DLF Forum 2015
Digital Curation using Archivematica and AtoM: DLF Forum 2015Digital Curation using Archivematica and AtoM: DLF Forum 2015
Digital Curation using Archivematica and AtoM: DLF Forum 2015Artefactual Systems - AtoM
 
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...Introducing Binder: A Web-based, Open Source Digital Preservation Management ...
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...Artefactual Systems - AtoM
 

Mehr von Artefactual Systems - AtoM (20)

Things I wish I'd known - AtoM tips, tricks, and gotchas
Things I wish I'd known - AtoM tips, tricks, and gotchasThings I wish I'd known - AtoM tips, tricks, and gotchas
Things I wish I'd known - AtoM tips, tricks, and gotchas
 
AtoM Community Update: 2019-05
AtoM Community Update: 2019-05AtoM Community Update: 2019-05
AtoM Community Update: 2019-05
 
Creating your own AtoM demo data set for re-use with Vagrant
Creating your own AtoM demo data set for re-use with VagrantCreating your own AtoM demo data set for re-use with Vagrant
Creating your own AtoM demo data set for re-use with Vagrant
 
AtoM Implementations
AtoM ImplementationsAtoM Implementations
AtoM Implementations
 
Looking Ahead: AtoM's governance, development, and future
Looking Ahead: AtoM's governance, development, and futureLooking Ahead: AtoM's governance, development, and future
Looking Ahead: AtoM's governance, development, and future
 
Contributing to the AtoM documentation
Contributing to the AtoM documentationContributing to the AtoM documentation
Contributing to the AtoM documentation
 
Installing AtoM with Ansible
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with Ansible
 
AtoM feature development
AtoM feature developmentAtoM feature development
AtoM feature development
 
Creating custom themes in AtoM
Creating custom themes in AtoMCreating custom themes in AtoM
Creating custom themes in AtoM
 
Installing and Upgrading AtoM
Installing and Upgrading AtoMInstalling and Upgrading AtoM
Installing and Upgrading AtoM
 
Command-Line 101
Command-Line 101Command-Line 101
Command-Line 101
 
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
 
An Introduction to AtoM, Archivematica, and Artefactual Systems
An Introduction to AtoM, Archivematica, and Artefactual SystemsAn Introduction to AtoM, Archivematica, and Artefactual Systems
An Introduction to AtoM, Archivematica, and Artefactual Systems
 
National Archives of Norway - AtoM and Archivematica intro workshop
National Archives of Norway - AtoM and Archivematica intro workshopNational Archives of Norway - AtoM and Archivematica intro workshop
National Archives of Norway - AtoM and Archivematica intro workshop
 
Artefactual and Open Source Development
Artefactual and Open Source DevelopmentArtefactual and Open Source Development
Artefactual and Open Source Development
 
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
 
AtoM Community Update 2016
AtoM Community Update 2016AtoM Community Update 2016
AtoM Community Update 2016
 
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...
Project Documentation with Sphinx (or, How I Learned to Stop Worrying and Lov...
 
Digital Curation using Archivematica and AtoM: DLF Forum 2015
Digital Curation using Archivematica and AtoM: DLF Forum 2015Digital Curation using Archivematica and AtoM: DLF Forum 2015
Digital Curation using Archivematica and AtoM: DLF Forum 2015
 
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...Introducing Binder: A Web-based, Open Source Digital Preservation Management ...
Introducing Binder: A Web-based, Open Source Digital Preservation Management ...
 

Kürzlich hochgeladen

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Kürzlich hochgeladen (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Constructing SQL queries for AtoM

  • 1. Constructing SQL Queries for AtoM Constructing SQL Queries for AtoM An overview of AtoM's data model and start constructing simple queries for reporting and data cleanup, among other uses, using MySQL Workbench.
  • 2. Outline Utilities to ease working with MySQL Data model overview and resources Explore the schema using SQL queries Practical examples
  • 3. MySQL Client Utilities MySQL command line interface ● Req command line access MySQL Workbench ● Runs locally ● Network connection to db PHPMyAdmin ● Web delivered ● Requires installation on server Sequel Pro (for macOS) Today I’ll be using MySQL Workbench ● Windows, macOS (OS X), Linux clients ● Don’t really want to install anything directly on Vagrant box as I purge it frequently
  • 4. MySQL Workbench Installing for use with AtoM Vagrant box ● Download from: ○ https://www.mysql.com/products/workbench/ ○ ...and run the installer ● Grant access to a user to connect to mysql from host machine ○ mysql -u root -h localhost -p ○ GRANT ALL ON *.* to root@'10.10.10.1' IDENTIFIED BY 'root'; ○ FLUSH PRIVILEGES; ● Launch MySQL Workbench ○ Connect to 10.10.10.10 ○ User: root ○ Pw: root
  • 5. AtoM’s ERD We are going to focus on a few specific tables https://wiki.accesstomemory.org/Development/ERDs
  • 7. Let’s look at an Archival description in AtoM: ● Fred Wah Fonds ● Examine the URL: ● http://10.10.10.10/fred-wah-fonds ● Slug is “fred-wah-fonds” SELECT * FROM slug WHERE slug.slug = "fred-wah-fonds"; We can browse all the slugs in this table: ● SELECT * FROM slug; Use slug.object_id to find the description: SELECT * FROM information_object WHERE id = 54206; Examine an Archival Description Tables: ● slug ● information_object
  • 8. Object Table A short diversion... Recalling the ORM discussion earlier: ● Most models extend ‘object’ model ● Object table row represented by object class/model ● Id’s for extended classes are derived from object class ● Ensures id’s are unique across different object types ● SELECT * FROM object; ● Note: class_name, id SELECT * FROM slug INNER JOIN object ON object.id = slug.object_id INNER JOIN information_object ON information_object.id = object.id WHERE slug.slug = "fred-wah-fonds"; Or drop the join on object entirely: SELECT * FROM slug INNER JOIN information_object ON information_object.id = slug.object_id WHERE slug.slug = "fred-wah-fonds";
  • 10. I18n Culture and translations The i18n tables contain translated strings ● 1 to many relationship between a table and i18n equivalent ● If a translation record is not available for chosen culture ○ Display strings from default culture i18n record ● If a translation record is available for chosen culture ○ Strings will be populated from this record based on selected culture ○ If the string is null for a specific field within i18n row ■ Fall back to i18n record matching system default culture Looking at the record for ‘fred-wah-fonds’: SELECT * FROM slug INNER JOIN information_object ON information_object.id = slug.object_id INNER JOIN information_object_i18n ON information_object_i18n.id = information_object.id WHERE slug.slug = "fred-wah-fonds"; Look for ‘extent_and_medium’ Note values for field ‘culture’
  • 11. I18n i18n translatable string examples from information_object_i18n
  • 12. Events and Actors From information_object, dates are linked to creators ● Dates → event table ● Creators → actor table Add join from information_object to event table: SELECT * FROM slug INNER JOIN information_object ON information_object.id = slug.object_id INNER JOIN event ON event.object_id = information_object.id WHERE slug.slug = "example-fonds"; Add a join to actor table: SELECT * FROM slug INNER JOIN information_object ON information_object.id = slug.object_id INNER JOIN event ON event.object_id = information_object.id INNER JOIN actor ON actor.id = event.actor_id INNER JOIN actor_i18n ON actor_i18n.id = actor.id WHERE slug.slug = "example-fonds"; 1. Let’s add a new event (creation date) to the information object ○ A new event row is created 2. Let’s add an authority record event ○ A new event record and an associated actor record created 3. Now add an authority record without dates ○ Event and actor created, but event will have null dates
  • 13. Terms Associating terms with objects ● Cross-reference table object_term_relation ● Example-fonds has an id of 57671 SELECT * FROM object_term_relation WHERE object_term_relation.object_id = 57671; Join in the term table: SELECT * FROM object_term_relation INNER JOIN term ON term.id = object_term_relation.term_id WHERE object_term_relation.object_id = 57671; Add another join to the term_i18n table: SELECT * FROM slug INNER JOIN information_object ON information_object.id = slug.object_id INNER JOIN object_term_relation ON object_term_relation.object_id = slug.object_id INNER JOIN term ON term.id = object_term_relation.term_id INNER JOIN term_i18n ON term_i18n.id = term.id WHERE slug.slug = "example-fonds"; Object Object_term_relation Term 1:many many:1
  • 14. Taxonomy That leads us to the taxonomy table ● Each term belongs to a taxonomy ● So when we found the terms on the previous slide: SELECT * FROM object_term_relation INNER JOIN term ON term.id = object_term_relation.term_id WHERE object_term_relation.object_id = 57671; We have the taxonomy_id from the term table Let’s add the taxonomy table with a join: SELECT * FROM object_term_relation INNER JOIN term ON term.id = object_term_relation.term_id INNER JOIN taxonomy ON taxonomy.id = term.taxonomy_id INNER JOIN taxonomy_i18n ON taxonomy_i18n.id = taxonomy.id WHERE object_term_relation.object_id = 57671 AND taxonomy_i18n.culture = 'en';
  • 15. Notes and Properties Both Notes and Properties have object_id as foreign key Tying these records back to the objects is simply: SELECT * FROM note INNER JOIN note_i18n ON note_i18n.id = note.id WHERE note.object_id = 57671; Have a look at type_id → maps to terms table: SELECT * FROM term INNER JOIN term_i18n ON term_i18n.id = term.id WHERE term.id = 174 AND term_i18n.culture = 'en'; Similarly for properties: SELECT * FROM property INNER JOIN property_i18n ON property_i18n.id = property.id WHERE property.object_id = 57671;
  • 16. Repository Repository details are contained in both the repository and actor tables ● Repositories have some fields in common with actor ● Need both to get all details SELECT * FROM repository WHERE repository.id = 57203; Add in the translatable strings: SELECT * FROM repository INNER JOIN repository_i18n ON repository_i18n.id = repository.id WHERE repository.id = 57203; Add in the fields from actor & actor_i18n: SELECT * FROM repository INNER JOIN repository_i18n ON repository_i18n.id = repository.id INNER JOIN actor on actor.id = repository.id INNER JOIN actor_i18n ON actor.id = actor_i18n.id WHERE repository.id = 57203;
  • 17. Nested Sets What are all those lft and rgt fields? ● Nested Sets! ● A way to record hierarchical relationships among similar entities ● https://en.wikipedia.org/wiki/Nested_set_model E.g. Information objects ● These are hierarchical objects ● Levels of Description (fonds, collection, item, part, series, etc) Let’s find a top level information_object ● Example-fonds (id: 57671, lft: 1638, rgt: 1641) ● Fred-wah-fonds (id: 54206, lft: 2, rgt: 1517) Let’s find all objects included in this object’s hierarchy: SELECT * FROM information_object WHERE information_object.lft >= 1638 AND information_object.rgt <= 1641 ORDER BY information_object.lft; Public domain image borrowed from https://en.wikipedia.org/wiki/Nested_set_model
  • 18. Update Queries Caution! ● Backups! ● Know how to restore from backups! ● Practice on a backup or offline copy ● Depending on what you’ve done, might need to: ○ Rebuild nested sets ○ Re-index
  • 19. What’s next? ● Set all ‘Draft’ status objects to ‘Published’: ○ UPDATE status SET status_id=160 WHERE type_id=158; ● Find info object id when slug not known: ○ SELECT id FROM information_object_i18n WHERE title='TITLEHERE'; ○ SELECT id FROM information_object_i18n WHERE title LIKE 'TITLEHE%'; ● Get a count of descriptions in database: ○ SELECT COUNT(*) FROM information_object_i18n; ● Find titles containing quote characters: ○ SELECT io.title, s.slug FROM information_object_i18n io JOIN slug s ON io.id = s.object_id WHERE io.title like '%"%'; ● See all note type terms and get a count of each: ○ SELECT term.id, term_i18n.name, COUNT(note.type_id) FROM term INNER JOIN term_i18n ON term.id = term_i18n.id INNER JOIN note ON term.id = note.type_id WHERE culture='en' GROUP BY note.type_id; See https://www.accesstomemory.org/docs/latest/admin-manual/maintenance/cli-tools/#common-atom-database-queries SQL Join reference: http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins