File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 2
2
Hosts the table tiers, user relations should be derived from.
3
3
"""
4
4
5
+ import inspect
5
6
from .table import Table
6
7
from .autopopulate import AutoPopulate
7
8
from .utils import from_camel_case , ClassProperty
@@ -186,3 +187,16 @@ def drop(self, force=False):
186
187
super ().drop ()
187
188
else :
188
189
raise DataJointError ('Cannot drop a Part directly. Delete from master instead' )
190
+
191
+ def alter (self , prompt = True , context = None ):
192
+ """
193
+ Alter the table definition from self.definition
194
+ """
195
+ # map "master" keyword to master table in context
196
+ if context is None :
197
+ frame = inspect .currentframe ().f_back
198
+ context = dict (frame .f_globals , ** frame .f_locals )
199
+ del frame
200
+ if self .master :
201
+ context ['master' ] = self .master
202
+ super ().alter (prompt , context )
Original file line number Diff line number Diff line change @@ -39,3 +39,26 @@ def test_alter():
39
39
restored = schema .connection .query ("SHOW CREATE TABLE " + Experiment .full_table_name ).fetchone ()[1 ]
40
40
assert_not_equal (altered , restored )
41
41
assert_equal (original , restored )
42
+
43
+
44
+ @schema
45
+ class TypeMaster (dj .Manual ):
46
+ definition = """
47
+ master_id : int
48
+ """
49
+
50
+ class Type (dj .Part ):
51
+ definition = """
52
+ -> master
53
+ """
54
+
55
+ definition1 = """
56
+ -> TypeMaster
57
+ """
58
+
59
+ def test_alter_part ():
60
+ original = schema .connection .query ("SHOW CREATE TABLE " + TypeMaster .Type .full_table_name ).fetchone ()[1 ]
61
+ TypeMaster .Type .definition = Experiment .definition1
62
+ TypeMaster .Type .alter (prompt = False )
63
+ altered = schema .connection .query ("SHOW CREATE TABLE " + TypeMaster .Type .full_table_name ).fetchone ()[1 ]
64
+ assert_equal (original , altered )
You can’t perform that action at this time.
0 commit comments