SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PDF
Namespaces
Sangeetha S
 
ODP
HTML5
Hatem Mahmoud
 
PPTX
Chapter 03 python libraries
Praveen M Jigajinni
 
PDF
Html table tags
eShikshak
 
PPTX
html-table
Dhirendra Chauhan
 
PPTX
An Introduction to Apache Pig
Sachin Vakkund
 
PPT
Html ppt
Iblesoft
 
PDF
Control Structures in Python
Sumit Satam
 
PPTX
Sql server ___________session_17(indexes)
Ehtisham Ali
 
PPT
Box Model
Amit Kumar Singh
 
DOCX
Index in sql server
Durgaprasad Yadav
 
PDF
Research 101 - Paper Writing with LaTeX
Jia-Bin Huang
 
PPT
Learning Html
Damian Gonz
 
PPTX
Xml ppt
seemadav1
 
PPT
Bootstrap Part - 1
EPAM Systems
 
PPTX
Data Structure
Karthikeyan A K
 
PPT
Xml Presentation-3
Sudharsan S
 
PPTX
If and select statement
Rahul Sharma
 
Namespaces
Sangeetha S
 
Chapter 03 python libraries
Praveen M Jigajinni
 
Html table tags
eShikshak
 
html-table
Dhirendra Chauhan
 
An Introduction to Apache Pig
Sachin Vakkund
 
Html ppt
Iblesoft
 
Control Structures in Python
Sumit Satam
 
Sql server ___________session_17(indexes)
Ehtisham Ali
 
Box Model
Amit Kumar Singh
 
Index in sql server
Durgaprasad Yadav
 
Research 101 - Paper Writing with LaTeX
Jia-Bin Huang
 
Learning Html
Damian Gonz
 
Xml ppt
seemadav1
 
Bootstrap Part - 1
EPAM Systems
 
Data Structure
Karthikeyan A K
 
Xml Presentation-3
Sudharsan S
 
If and select statement
Rahul Sharma
 

Similar to Constructing SQL queries for AtoM (20)

PDF
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nicolas Thon
 
PPT
Linq in C# 3.0: An Overview
pradeepkothiyal
 
PDF
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 
ZIP
Day 2
Pat Zearfoss
 
PDF
Core data in Swfit
allanh0526
 
ODP
Cool bonsai cool - an introduction to ElasticSearch
clintongormley
 
PDF
#SalesforceSaturday : Salesforce BIG Objects Explained
Atul Gupta(8X)
 
PPS
Creating classes and applications in java
Gujarat Technological University
 
PPSX
Dynamic memory allocation
Moniruzzaman _
 
PPT
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
PDF
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
PDF
Java Web Programming on Google Cloud Platform [2/3] : Datastore
IMC Institute
 
PDF
Bubbles – Virtual Data Objects
Stefan Urbanek
 
PDF
Introduction to Datastore
Software Park Thailand
 
PPTX
NHibernate
gabrielcerutti
 
PPTX
WEKA: Data Mining Input Concepts Instances And Attributes
DataminingTools Inc
 
PPTX
WEKA:Data Mining Input Concepts Instances And Attributes
weka Content
 
PDF
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
PPT
Itemscript, a specification for RESTful JSON integration
{item:foo}
 
PPTX
08ui.pptx
KabadaSori
 
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nicolas Thon
 
Linq in C# 3.0: An Overview
pradeepkothiyal
 
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 
Core data in Swfit
allanh0526
 
Cool bonsai cool - an introduction to ElasticSearch
clintongormley
 
#SalesforceSaturday : Salesforce BIG Objects Explained
Atul Gupta(8X)
 
Creating classes and applications in java
Gujarat Technological University
 
Dynamic memory allocation
Moniruzzaman _
 
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
IMC Institute
 
Bubbles – Virtual Data Objects
Stefan Urbanek
 
Introduction to Datastore
Software Park Thailand
 
NHibernate
gabrielcerutti
 
WEKA: Data Mining Input Concepts Instances And Attributes
DataminingTools Inc
 
WEKA:Data Mining Input Concepts Instances And Attributes
weka Content
 
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
Itemscript, a specification for RESTful JSON integration
{item:foo}
 
08ui.pptx
KabadaSori
 
Ad

More from Artefactual Systems - AtoM (20)

PDF
Artefactual AtoM Priorities November 2024
Artefactual Systems - AtoM
 
PPTX
CSV import in AtoM
Artefactual Systems - AtoM
 
PDF
AtoM Community Update: 2019-05
Artefactual Systems - AtoM
 
PPTX
Creating your own AtoM demo data set for re-use with Vagrant
Artefactual Systems - AtoM
 
PPTX
Building the Future Together: AtoM3, Governance, and the Sustainability of Op...
Artefactual Systems - AtoM
 
PPTX
AtoM Implementations
Artefactual Systems - AtoM
 
PPTX
AtoM Data Migrations
Artefactual Systems - AtoM
 
PPTX
Looking Ahead: AtoM's governance, development, and future
Artefactual Systems - AtoM
 
PPTX
Contributing to the AtoM documentation
Artefactual Systems - AtoM
 
PDF
Installing AtoM with Ansible
Artefactual Systems - AtoM
 
PDF
AtoM feature development
Artefactual Systems - AtoM
 
PDF
Installing and Upgrading AtoM
Artefactual Systems - AtoM
 
PPTX
Command-Line 101
Artefactual Systems - AtoM
 
PPTX
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
Artefactual Systems - AtoM
 
PPTX
An Introduction to AtoM, Archivematica, and Artefactual Systems
Artefactual Systems - AtoM
 
PDF
National Archives of Norway - AtoM and Archivematica intro workshop
Artefactual Systems - AtoM
 
PPTX
Introducing Access to Memory
Artefactual Systems - AtoM
 
PPTX
Artefactual and Open Source Development
Artefactual Systems - AtoM
 
PPTX
AtoM, Authenticity, and the Chain of Custody
Artefactual Systems - AtoM
 
PPTX
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Artefactual Systems - AtoM
 
Artefactual AtoM Priorities November 2024
Artefactual Systems - AtoM
 
CSV import in AtoM
Artefactual Systems - AtoM
 
AtoM Community Update: 2019-05
Artefactual Systems - AtoM
 
Creating your own AtoM demo data set for re-use with Vagrant
Artefactual Systems - AtoM
 
Building the Future Together: AtoM3, Governance, and the Sustainability of Op...
Artefactual Systems - AtoM
 
AtoM Implementations
Artefactual Systems - AtoM
 
AtoM Data Migrations
Artefactual Systems - AtoM
 
Looking Ahead: AtoM's governance, development, and future
Artefactual Systems - AtoM
 
Contributing to the AtoM documentation
Artefactual Systems - AtoM
 
Installing AtoM with Ansible
Artefactual Systems - AtoM
 
AtoM feature development
Artefactual Systems - AtoM
 
Installing and Upgrading AtoM
Artefactual Systems - AtoM
 
Command-Line 101
Artefactual Systems - AtoM
 
AtoM and Vagrant: Installing and Configuring the AtoM Vagrant Box for Local T...
Artefactual Systems - AtoM
 
An Introduction to AtoM, Archivematica, and Artefactual Systems
Artefactual Systems - AtoM
 
National Archives of Norway - AtoM and Archivematica intro workshop
Artefactual Systems - AtoM
 
Introducing Access to Memory
Artefactual Systems - AtoM
 
Artefactual and Open Source Development
Artefactual Systems - AtoM
 
AtoM, Authenticity, and the Chain of Custody
Artefactual Systems - AtoM
 
Technologie Proche: Imagining the Archival Systems of Tomorrow With the Tools...
Artefactual Systems - AtoM
 
Ad

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Python basic programing language for automation
DanialHabibi2
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
July Patch Tuesday
Ivanti
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

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