Skip to content

Commit f881379

Browse files
committed
2 parents 97d1e53 + 3320e22 commit f881379

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Release notes
22

3-
### 0.14.1 -- Feb 21, 2023
3+
### Upcoming
4+
- Fixed - Fix altering a part table that uses the "master" keyword - PR [#991](https://github.com/datajoint/datajoint-python/pull/991)
5+
6+
### 0.14.1 -- Apr 05, 2023
47
- Fixed - .ipynb output in tutorials is not visible in dark mode ([#1078](https://github.com/datajoint/datajoint-python/issues/1078) PR [#1080](https://github.com/datajoint/datajoint-python/pull/1080))
58

69
### 0.14.0 -- Feb 13, 2023

datajoint/user_tables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,7 @@ def drop(self, force=False):
238238
raise DataJointError(
239239
"Cannot drop a Part directly. Delete from master instead"
240240
)
241+
242+
def alter(self, prompt=True, context=None):
243+
# without context, use declaration context which maps master keyword to master table
244+
super().alter(prompt=prompt, context=context or self.declaration_context)

tests/test_alter.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from nose.tools import assert_equal, assert_not_equal
2+
import re
23
from .schema import *
34

45

@@ -27,6 +28,33 @@ class Experiment(dj.Imported):
2728
"""
2829

2930

31+
@schema
32+
class Parent(dj.Manual):
33+
definition = """
34+
parent_id: int
35+
"""
36+
37+
class Child(dj.Part):
38+
definition = """
39+
-> Parent
40+
"""
41+
definition_new = """
42+
-> master
43+
---
44+
child_id=null: int
45+
"""
46+
47+
class Grandchild(dj.Part):
48+
definition = """
49+
-> master.Child
50+
"""
51+
definition_new = """
52+
-> master.Child
53+
---
54+
grandchild_id=null: int
55+
"""
56+
57+
3058
def test_alter():
3159
original = schema.connection.query(
3260
"SHOW CREATE TABLE " + Experiment.full_table_name
@@ -44,3 +72,25 @@ def test_alter():
4472
).fetchone()[1]
4573
assert_not_equal(altered, restored)
4674
assert_equal(original, restored)
75+
76+
77+
def test_alter_part():
78+
# https://github.com/datajoint/datajoint-python/issues/936
79+
80+
def verify_alter(table, attribute_sql):
81+
definition_original = schema.connection.query(
82+
f"SHOW CREATE TABLE {table.full_table_name}"
83+
).fetchone()[1]
84+
table.definition = table.definition_new
85+
table.alter(prompt=False)
86+
definition_new = schema.connection.query(
87+
f"SHOW CREATE TABLE {table.full_table_name}"
88+
).fetchone()[1]
89+
assert (
90+
re.sub(f"{attribute_sql},\n ", "", definition_new) == definition_original
91+
)
92+
93+
verify_alter(table=Parent.Child, attribute_sql="`child_id` .* DEFAULT NULL")
94+
verify_alter(
95+
table=Parent.Grandchild, attribute_sql="`grandchild_id` .* DEFAULT NULL"
96+
)

0 commit comments

Comments
 (0)