215 lines
6.0 KiB
Markdown
Executable File
215 lines
6.0 KiB
Markdown
Executable File
---
|
|
gitea: none
|
|
include_toc: true
|
|
---
|
|
|
|
# AtoM SQL Queries
|
|
|
|
See also here: [Common AtoM database queries](https://www.accesstomemory.org/en/docs/2.6/admin-manual/maintenance/common-atom-queries/)
|
|
|
|
## recreate DB
|
|
|
|
```
|
|
php symfony propel:insert-sql
|
|
/* or */
|
|
DROP database atom25dbtest;
|
|
CREATE DATABASE `my-db` CHARACTER SET utf8 COLLATE utf8_unicode_ci;
|
|
```
|
|
|
|
dann webinstaller machen. evtl. noch `config/config.php` löschen.
|
|
|
|
## delete all archival descriptions
|
|
|
|
``` sql
|
|
DELETE FROM information_object WHERE id <> 1;
|
|
```
|
|
|
|
## get Repository ID by slug
|
|
|
|
``` sql
|
|
select a.id, a.parent_id, a.repository_id, b.title
|
|
from information_object a
|
|
left join information_object_i18n b on a.id = b.id
|
|
where a.id = (
|
|
select object_id from slug
|
|
where slug = 'historische-glasdias-2'
|
|
);
|
|
```
|
|
|
|
## Get all descriptions recursively (parent --> children)
|
|
|
|
```
|
|
WITH RECURSIVE cte (id, identifier, parent_id) AS (
|
|
SELECT io.id, io.identifier, io.parent_id
|
|
FROM information_object io
|
|
WHERE io.parent_id = 505795
|
|
UNION ALL
|
|
SELECT io2.id, io2.identifier, io2.parent_id
|
|
FROM information_object io2
|
|
INNER JOIN cte
|
|
ON io2.parent_id = cte.id
|
|
)
|
|
SELECT cte.id, cte.parent_id, cte.identifier, io18.title, p18.value AS PID, s.slug
|
|
FROM cte
|
|
LEFT JOIN information_object_i18n io18
|
|
ON io18.id = cte.id
|
|
LEFT JOIN property as p1
|
|
ON p1.object_id = cte.id
|
|
LEFT JOIN property_i18n as p18
|
|
ON p18.id = p1.id
|
|
LEFT JOIN slug AS s
|
|
ON s.object_id = cte.id
|
|
WHERE p1.name LIKE 'PID';
|
|
```
|
|
|
|
## Get all descriptions by alternative identifier
|
|
|
|
replace `SRG-Test:%`
|
|
|
|
```
|
|
mysql -u root -p -e "use atom; select io.title, s.slug, p2.value from property as p1 left join property_i18n p2 on p1.id = p2.id left join slug s on s.object_id = p1.object_id left join information_object_i18n io on io.id = p1.object_id where p1.name like 'PID' and p2.value like 'SRG-Test:%';" > pid_with_SRG-Test.csv
|
|
|
|
# readable query:
|
|
SELECT io.title, s.slug, p2.value
|
|
FROM property as p1
|
|
LEFT JOIN property_i18n p2
|
|
ON p1.id = p2.id
|
|
LEFT JOIN slug s
|
|
ON s.object_id = p1.object_id
|
|
LEFT JOIN information_object_i18n io
|
|
ON io.id = p1.object_id
|
|
WHERE p1.name LIKE 'PID'
|
|
AND p2.value LIKE 'SRG-Test:%';
|
|
```
|
|
|
|
## Get all authority records
|
|
|
|
```
|
|
mysql -e "USE atom25db; SELECT a.*, b.* FROM actor LEFT JOIN actor_i18n B ON A.ID = B.ID;" > /home/docuteam/authorityrecords.csv
|
|
```
|
|
|
|
Then open CSV, remove 2nd "id"-column.
|
|
|
|
Entity types:
|
|
- 131: Corporate body
|
|
- 132: Person
|
|
|
|
Description status:
|
|
- 221: Final
|
|
- 222: Revised
|
|
- 223: Draft
|
|
|
|
Level of detail:
|
|
- 224: Full
|
|
- 225: Partial
|
|
- 226: Minimal
|
|
|
|
## get all authority records
|
|
|
|
``` sql
|
|
select distinct /* with or without distinct? */
|
|
actor_i18n.authorized_form_of_name,
|
|
actor.entity_type_id
|
|
from actor_i18n
|
|
join actor on actor.id = actor_i18n.id
|
|
join object on object.id = actor.id
|
|
join event on event.actor_id = actor.id
|
|
where object.class_name = "QubitActor"
|
|
and actor_i18n.culture = "en";
|
|
|
|
/* query to test on BIS: */
|
|
SELECT
|
|
actor_i18n.id AS actor_i18n__id,
|
|
actor_i18n.authorized_form_of_name AS actor_i18n__authorized_form_of_name,
|
|
actor_i18n.dates_of_existence AS actor_i18n__dates_of_existence,
|
|
actor_i18n.history AS actor_i18n__history,
|
|
actor_i18n.places AS actor_i18n__places,
|
|
actor_i18n.legal_status AS actor_i18n__legal_status,
|
|
actor_i18n.functions AS actor_i18n__functions,
|
|
actor_i18n.mandates AS actor_i18n__mandates,
|
|
actor_i18n.internal_structures AS actor_i18n__internal_structures,
|
|
actor_i18n.general_context AS actor_i18n__general_context,
|
|
actor_i18n.institution_responsible_identifier AS actor_i18n__institution_responsible_identifier,
|
|
actor_i18n.rules AS actor_i18n__rules,
|
|
actor_i18n.sources AS actor_i18n__sources,
|
|
actor_i18n.culture AS actor_i18n__culture,
|
|
actor.id AS actor__id,
|
|
actor.entity_type_id AS actor__entity_type_id,
|
|
actor.corporate_body_identifiers AS actor__corporate_body_identifiers,
|
|
actor.description_status_id AS actor__description_status_id,
|
|
actor.description_detail_id AS actor__description_detail_id,
|
|
actor.description_identifier AS actor__description_identifier,
|
|
actor.source_standard AS actor__source_standard,
|
|
actor.parent_id AS actor__parent_id,
|
|
actor.lft AS actor__lft,
|
|
actor.rgt AS actor__rgt,
|
|
actor.source_culture AS actor__source_culture
|
|
FROM actor_i18n
|
|
JOIN actor ON actor.id = actor_i18n.id
|
|
JOIN object ON object.id = actor.id
|
|
WHERE object.class_name = "QubitActor";
|
|
```
|
|
|
|
## get all places
|
|
|
|
Taxonomy_id of subjects is *42*
|
|
|
|
```
|
|
mysql -e "USE atom25db; SELECT a.id, a.taxonomy_id, a.code, a.parent_id, a.source_culture, b.name, b.culture FROM term a LEFT JOIN term_i18n b ON a.id = b.id WHERE a.taxonomy_id = 42 ORDER BY a.id ASC;" > /home/docuteam/places.csv
|
|
```
|
|
|
|
## delete places
|
|
|
|
### only places containing "Bahnhof"
|
|
|
|
```
|
|
DELETE FROM term
|
|
WHERE term.taxonomy_id = 42
|
|
AND term.id = (SELECT term_i18n.id FROM term_i18n WHERE term_i18n.name LIKE '%Bahnhof%');
|
|
```
|
|
|
|
### all places
|
|
|
|
```
|
|
DELETE FROM term WHERE term.taxonomy_id = 42;
|
|
```
|
|
|
|
Anschliessend build nested set und search index!
|
|
|
|
## count all archival descriptions
|
|
|
|
``` sql
|
|
SELECT COUNT(*) FROM information_object WHERE id <> 1;
|
|
```
|
|
|
|
## get all subjects
|
|
|
|
Taxonomy_id of subjects is *35*
|
|
|
|
```
|
|
mysql -e "USE atom25db; SELECT a.id, a.taxonomy_id, a.code, a.parent_id, a.source_culture, b.name, b.culture FROM term a LEFT JOIN term_i18n b ON a.id = b.id WHERE a.taxonomy_id = 35 ORDER BY a.id ASC;" > /home/docuteam/subjects.csv
|
|
```
|
|
|
|
## Get all Identifiers
|
|
|
|
``` sql
|
|
select identifier, id, parent_id
|
|
from information_object
|
|
where identifier IS NOT NULL
|
|
and identifier not like '#%'
|
|
and identifier != '?'
|
|
order by cast(identifier as unsigned) asc;
|
|
```
|
|
|
|
## Update information_object_i18n based on joined data
|
|
|
|
``` sql
|
|
UPDATE information_object_i18n AS io
|
|
LEFT JOIN property p1
|
|
ON p1.object_id = io.id
|
|
LEFT JOIN property_i18n p2
|
|
ON p1.id = p2.id
|
|
SET io.title = CONCAT('recovery_failed_', io.title)
|
|
WHERE p1.name LIKE 'PID'
|
|
AND p2.value = 'CH-000-0:1234';
|
|
``` |