16
16
"NULL" ,
17
17
} # SQL literals to be used without quotes (case insensitive)
18
18
EXTERNAL_TABLE_ROOT = "~external"
19
- METADATA_ATTRIBUTES_SQL = ["`_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" ]
19
+ METADATA_ATTRIBUTES_SQL = [
20
+ "`_{full_table_name}_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"
21
+ ]
22
+ LONGEST_METADATA_ATTRIBUTE = len ("__timestamp" )
20
23
21
24
TYPE_PATTERN = {
22
25
k : re .compile (v , re .I )
@@ -293,11 +296,14 @@ def declare(full_table_name, definition, context):
293
296
:param context: dictionary of objects that might be referred to in the table
294
297
:return: SQL CREATE TABLE statement, list of external stores used
295
298
"""
296
- table_name = full_table_name .strip ("`" ).split ("." )[1 ]
297
- if len (table_name ) > MAX_TABLE_NAME_LENGTH :
299
+ if (
300
+ len (full_table_name .replace ("`" , "" )) + LONGEST_METADATA_ATTRIBUTE
301
+ > MAX_TABLE_NAME_LENGTH
302
+ ):
298
303
raise DataJointError (
299
304
"Table name `{name}` exceeds the max length of {max_length}" .format (
300
- name = table_name , max_length = MAX_TABLE_NAME_LENGTH
305
+ name = full_table_name .replace ("`" , "" ),
306
+ max_length = MAX_TABLE_NAME_LENGTH - LONGEST_METADATA_ATTRIBUTE ,
301
307
)
302
308
)
303
309
@@ -309,7 +315,12 @@ def declare(full_table_name, definition, context):
309
315
index_sql ,
310
316
external_stores ,
311
317
) = prepare_declare (definition , context )
312
- attribute_sql .extend (METADATA_ATTRIBUTES_SQL )
318
+ attribute_sql .extend (
319
+ [
320
+ attr .format (full_table_name = full_table_name .replace ("`" , "" ))
321
+ for attr in METADATA_ATTRIBUTES_SQL
322
+ ]
323
+ )
313
324
314
325
if not primary_key :
315
326
raise DataJointError ("Table must have a primary key" )
@@ -412,7 +423,6 @@ def alter(definition, old_definition, context):
412
423
index_sql ,
413
424
external_stores ,
414
425
) = prepare_declare (definition , context )
415
- attribute_sql .extend (METADATA_ATTRIBUTES_SQL )
416
426
(
417
427
table_comment_ ,
418
428
primary_key_ ,
@@ -421,7 +431,6 @@ def alter(definition, old_definition, context):
421
431
index_sql_ ,
422
432
external_stores_ ,
423
433
) = prepare_declare (old_definition , context )
424
- attribute_sql_ .extend (METADATA_ATTRIBUTES_SQL )
425
434
426
435
# analyze differences between declarations
427
436
sql = list ()
0 commit comments