|
| 1 | +# What's New in DataJoint 2.1 |
| 2 | + |
| 3 | +DataJoint 2.1 adds **PostgreSQL as a production backend**, **enhanced diagram visualization**, and **singleton tables**. |
| 4 | + |
| 5 | +> **Upgrading from 2.0?** No breaking changes. All existing code continues to work. New features are purely additive. |
| 6 | +
|
| 7 | +> **Citation:** Yatsenko D, Nguyen TT. *DataJoint 2.0: A Computational Substrate for Agentic Scientific Workflows.* arXiv:2602.16585. 2026. [doi:10.48550/arXiv.2602.16585](https://doi.org/10.48550/arXiv.2602.16585) |
| 8 | +
|
| 9 | +## PostgreSQL Backend |
| 10 | + |
| 11 | +DataJoint now supports PostgreSQL 15+ as a production database backend alongside MySQL 8+. The adapter architecture generates backend-specific SQL while maintaining a consistent API — the same table definitions, queries, and pipeline logic work on both backends. |
| 12 | + |
| 13 | +```bash |
| 14 | +export DJ_BACKEND=postgresql |
| 15 | +export DJ_HOST=localhost |
| 16 | +export DJ_PORT=5432 |
| 17 | +``` |
| 18 | + |
| 19 | +Or configure programmatically: |
| 20 | + |
| 21 | +```python |
| 22 | +dj.config['database.backend'] = 'postgresql' |
| 23 | +``` |
| 24 | + |
| 25 | +All core types (`int32`, `float64`, `varchar`, `uuid`, `json`), codec types (`<blob>`, `<attach>`, `<object@>`), query operations, foreign keys, indexes, and auto-populate work identically across backends. Backend-specific differences are handled internally by the adapter layer. |
| 26 | + |
| 27 | +See [Database Backends](../reference/specs/database-backends.md) for the full specification. |
| 28 | + |
| 29 | +## Diagram Enhancements |
| 30 | + |
| 31 | +`dj.Diagram` gains several visualization features for working with complex, multi-schema pipelines. |
| 32 | + |
| 33 | +### Layout Direction |
| 34 | + |
| 35 | +Control the flow direction of diagrams: |
| 36 | + |
| 37 | +```python |
| 38 | +# Horizontal layout |
| 39 | +dj.config.display.diagram_direction = "LR" |
| 40 | + |
| 41 | +# Or temporarily |
| 42 | +with dj.config.override(display__diagram_direction="LR"): |
| 43 | + dj.Diagram(schema).draw() |
| 44 | +``` |
| 45 | + |
| 46 | +| Value | Description | |
| 47 | +|-------|-------------| |
| 48 | +| `"TB"` | Top to bottom (default) | |
| 49 | +| `"LR"` | Left to right | |
| 50 | + |
| 51 | +### Mermaid Output |
| 52 | + |
| 53 | +Generate [Mermaid](https://mermaid.js.org/) syntax for embedding diagrams in Markdown, GitHub, or web documentation: |
| 54 | + |
| 55 | +```python |
| 56 | +print(dj.Diagram(schema).make_mermaid()) |
| 57 | +``` |
| 58 | + |
| 59 | +Save directly to `.mmd` or `.mermaid` files: |
| 60 | + |
| 61 | +```python |
| 62 | +dj.Diagram(schema).save("pipeline.mmd") |
| 63 | +``` |
| 64 | + |
| 65 | +### Schema Grouping |
| 66 | + |
| 67 | +Multi-schema diagrams automatically group tables into visual clusters by database schema. The cluster label shows the Python module name when available, following the DataJoint convention of one module per schema. |
| 68 | + |
| 69 | +```python |
| 70 | +combined = dj.Diagram(schema1) + dj.Diagram(schema2) |
| 71 | +combined.draw() # tables grouped by schema |
| 72 | +``` |
| 73 | + |
| 74 | +### Collapsing Schemas |
| 75 | + |
| 76 | +For high-level pipeline views, collapse entire schemas into single nodes: |
| 77 | + |
| 78 | +```python |
| 79 | +# Show schema1 expanded, schema2 as a single node with table count |
| 80 | +dj.Diagram(schema1) + dj.Diagram(schema2).collapse() |
| 81 | +``` |
| 82 | + |
| 83 | +The **"expanded wins" rule** applies: if a table appears in both a collapsed and non-collapsed diagram, it stays expanded. This allows showing specific tables while collapsing the rest: |
| 84 | + |
| 85 | +```python |
| 86 | +# Subject is expanded, rest of analysis schema is collapsed |
| 87 | +dj.Diagram(Subject) + dj.Diagram(analysis).collapse() |
| 88 | +``` |
| 89 | + |
| 90 | +See [Diagram Specification](../reference/specs/diagram.md) for the full reference. |
| 91 | + |
| 92 | +## Singleton Tables |
| 93 | + |
| 94 | +A **singleton table** holds at most one row. Declare it with no attributes in the primary key section: |
| 95 | + |
| 96 | +```python |
| 97 | +@schema |
| 98 | +class Config(dj.Lookup): |
| 99 | + definition = """ |
| 100 | + # Global configuration |
| 101 | + --- |
| 102 | + setting1 : varchar(100) |
| 103 | + setting2 : int32 |
| 104 | + """ |
| 105 | +``` |
| 106 | + |
| 107 | +| Operation | Result | |
| 108 | +|-----------|--------| |
| 109 | +| Insert | Works without specifying a key | |
| 110 | +| Second insert | Raises `DuplicateError` | |
| 111 | +| `fetch1()` | Returns the single row | |
| 112 | + |
| 113 | +Useful for global configuration, pipeline parameters, and summary statistics. |
| 114 | + |
| 115 | +See [Table Declaration](../reference/specs/table-declaration.md#25-singleton-tables-empty-primary-keys) for details. |
| 116 | + |
| 117 | +## See Also |
| 118 | + |
| 119 | +- [Database Backends](../reference/specs/database-backends.md) — Full backend specification |
| 120 | +- [Diagram Specification](../reference/specs/diagram.md) — Diagram reference |
| 121 | +- [Table Declaration](../reference/specs/table-declaration.md) — Singleton tables |
| 122 | +- [Configure Database](../how-to/configure-database.md) — Connection setup for both backends |
| 123 | +- [What's New in 2.0](whats-new-2.md) — Previous release |
| 124 | +- [What's New in 2.2](whats-new-22.md) — Next release |
| 125 | +- [Release Notes (v2.1.0)](https://github.com/datajoint/datajoint-python/releases/tag/v2.1.0) — GitHub changelog |
0 commit comments