1616 "NULL" ,
1717} # SQL literals to be used without quotes (case insensitive)
1818EXTERNAL_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" )
2023
2124TYPE_PATTERN = {
2225 k : re .compile (v , re .I )
@@ -293,11 +296,14 @@ def declare(full_table_name, definition, context):
293296 :param context: dictionary of objects that might be referred to in the table
294297 :return: SQL CREATE TABLE statement, list of external stores used
295298 """
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+ ):
298303 raise DataJointError (
299304 "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 ,
301307 )
302308 )
303309
@@ -309,7 +315,12 @@ def declare(full_table_name, definition, context):
309315 index_sql ,
310316 external_stores ,
311317 ) = 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+ )
313324
314325 if not primary_key :
315326 raise DataJointError ("Table must have a primary key" )
@@ -412,7 +423,6 @@ def alter(definition, old_definition, context):
412423 index_sql ,
413424 external_stores ,
414425 ) = prepare_declare (definition , context )
415- attribute_sql .extend (METADATA_ATTRIBUTES_SQL )
416426 (
417427 table_comment_ ,
418428 primary_key_ ,
@@ -421,7 +431,6 @@ def alter(definition, old_definition, context):
421431 index_sql_ ,
422432 external_stores_ ,
423433 ) = prepare_declare (old_definition , context )
424- attribute_sql_ .extend (METADATA_ATTRIBUTES_SQL )
425434
426435 # analyze differences between declarations
427436 sql = list ()
0 commit comments