Skip to content

Commit a3dcabf

Browse files
Simplify delete_table_lineages call and update spec types
- Remove redundant lineage_table_exists check in table.py (already handled inside delete_table_lineages) - Update spec examples to use core DataJoint types (uint32, uint16) instead of native types (int) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6691f65 commit a3dcabf

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

docs/src/design/semantic-matching-spec.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ Semantic matching is enabled by default in DataJoint 2.0. For most well-designed
2525
# Two tables with generic 'id' attribute
2626
class Student(dj.Manual):
2727
definition = """
28-
id : int
28+
id : uint32
2929
---
3030
name : varchar(100)
3131
"""
3232

3333
class Course(dj.Manual):
3434
definition = """
35-
id : int
35+
id : uint32
3636
---
3737
title : varchar(100)
3838
"""
@@ -57,7 +57,7 @@ Student().join(Course(), semantic_check=False) # OK, but be careful!
5757
```python
5858
class Student(dj.Manual):
5959
definition = """
60-
student_id : int
60+
student_id : uint32
6161
---
6262
name : varchar(100)
6363
"""
@@ -235,23 +235,23 @@ schema_name.table_name.attribute_name
235235
```python
236236
class Session(dj.Manual): # table: session
237237
definition = """
238-
session_id : int
238+
session_id : uint32
239239
---
240-
date : date
240+
session_date : date
241241
"""
242242

243243
class Trial(dj.Manual): # table: trial
244244
definition = """
245245
-> Session
246-
trial_num : int
246+
trial_num : uint16
247247
---
248248
stimulus : varchar(100)
249249
"""
250250
```
251251

252252
Lineages:
253253
- `Session.session_id``myschema.session.session_id` (native PK)
254-
- `Session.date``None` (native secondary)
254+
- `Session.session_date``None` (native secondary)
255255
- `Trial.session_id``myschema.session.session_id` (inherited via FK)
256256
- `Trial.trial_num``myschema.trial.trial_num` (native PK)
257257
- `Trial.stimulus``None` (native secondary)
@@ -385,7 +385,7 @@ run schema.rebuild_lineage() on this schema to correct the lineage.
385385
```python
386386
class Student(dj.Manual):
387387
definition = """
388-
student_id : int
388+
student_id : uint32
389389
---
390390
name : varchar(100)
391391
"""
@@ -407,16 +407,16 @@ Student() * Enrollment()
407407
```python
408408
class TableA(dj.Manual):
409409
definition = """
410-
id : int
410+
id : uint32
411411
---
412-
value_a : int
412+
value_a : int32
413413
"""
414414

415415
class TableB(dj.Manual):
416416
definition = """
417-
id : int
417+
id : uint32
418418
---
419-
value_b : int
419+
value_b : int32
420420
"""
421421

422422
# Error: 'id' has different lineages
@@ -434,22 +434,22 @@ TableA().join(TableB(), semantic_check=False)
434434
```python
435435
class Session(dj.Manual):
436436
definition = """
437-
session_id : int
437+
session_id : uint32
438438
---
439-
date : date
439+
session_date : date
440440
"""
441441

442442
class Trial(dj.Manual):
443443
definition = """
444444
-> Session
445-
trial_num : int
445+
trial_num : uint16
446446
"""
447447

448448
class Response(dj.Computed):
449449
definition = """
450450
-> Trial
451451
---
452-
response_time : float
452+
response_time : float64
453453
"""
454454

455455
# All work: session_id traces back to Session in all tables
@@ -463,21 +463,21 @@ Trial() * Response()
463463
```python
464464
class Course(dj.Manual):
465465
definition = """
466-
course_id : int
466+
course_id : int unsigned
467467
---
468468
title : varchar(100)
469469
"""
470470

471471
class FavoriteCourse(dj.Manual):
472472
definition = """
473-
student_id : int
473+
student_id : int unsigned
474474
---
475475
-> Course
476476
"""
477477

478478
class RequiredCourse(dj.Manual):
479479
definition = """
480-
major_id : int
480+
major_id : int unsigned
481481
---
482482
-> Course
483483
"""
@@ -491,17 +491,17 @@ FavoriteCourse() * RequiredCourse()
491491
```python
492492
class Person(dj.Manual):
493493
definition = """
494-
person_id : int
494+
person_id : int unsigned
495495
---
496-
name : varchar(100)
496+
full_name : varchar(100)
497497
"""
498498

499499
class Marriage(dj.Manual):
500500
definition = """
501501
-> Person.proj(husband='person_id')
502502
-> Person.proj(wife='person_id')
503503
---
504-
date : date
504+
marriage_date : date
505505
"""
506506

507507
# husband and wife both have lineage: schema.person.person_id

src/datajoint/table.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,9 @@ def drop_quick(self):
674674
"""
675675
if self.is_declared:
676676
# Clean up lineage entries for this table
677-
from .lineage import delete_table_lineages, lineage_table_exists
677+
from .lineage import delete_table_lineages
678678

679-
if lineage_table_exists(self.connection, self.database):
680-
delete_table_lineages(self.connection, self.database, self.table_name)
679+
delete_table_lineages(self.connection, self.database, self.table_name)
681680

682681
query = "DROP TABLE %s" % self.full_table_name
683682
self.connection.query(query)

0 commit comments

Comments
 (0)