-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_db.py
More file actions
56 lines (46 loc) · 1.71 KB
/
init_db.py
File metadata and controls
56 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from app import app, db, IdentifierType, ObjectType
def init_identifier_types():
"""Insert default identifier types if not present."""
defaults = [
("ark", "Archival Resource Key", "https://n2t.net/ark:/83794/<id>"),
("luna", "LUNA Image ID", "https://images.is.ed.ac.uk/luna/servlet/detail/<id>"),
("arch", "Archipelago UUID", "https://digital.collections.ed.ac.uk/do/<id>"),
("file", "Source Filename", None),
("cantaloupe", "IIIF Cantaloupe ID",
"https://digital.collections.ed.ac.uk/cantaloupe/iiif/2/<id>/full/600,/0/default.jpg")
]
for shortcode, desc, url in defaults:
row = IdentifierType.query.filter_by(shortcode=shortcode).first()
if not row:
db.session.add(
IdentifierType(
shortcode=shortcode,
description=desc,
url_construct=url
)
)
db.session.commit()
print("Identifier types initialized.")
def init_object_types():
"""Insert minimal default object types."""
defaults = [
("Image", None), # no URL construct at object level
]
for name, url in defaults:
row = ObjectType.query.filter_by(name=name).first()
if not row:
db.session.add(
ObjectType(
name=name,
url_construct=url
)
)
db.session.commit()
print("Object types initialized.")
if __name__ == "__main__":
with app.app_context():
print("Creating tables (if not existing)…")
db.create_all()
init_identifier_types()
init_object_types()
print("Database initialization complete.")