@@ -99,8 +99,8 @@ def upload_metadata(dir_path: Path = '.', unit_id: str = None, verbose: bool = F
99
99
event_handler = FileSystemEventHandler ()
100
100
firestore_db = firestore .Client ()
101
101
# Get the unit reference to link metadata to unit.
102
- unit_metadata_ref = firestore_db .document (f'units/{ unit_id } /metadata ' )
103
- metadata_records_ref = unit_metadata_ref .collection ('records ' )
102
+ unit_ref = firestore_db .document (f'units/{ unit_id } ' )
103
+ metadata_records_ref = unit_ref .collection ('metadata ' )
104
104
105
105
def handleEvent (event ):
106
106
if event .is_directory :
@@ -115,19 +115,19 @@ def handleEvent(event):
115
115
record = json .loads (Path (event .src_path ).read_text ())
116
116
117
117
# Unpack the envelope.
118
- collection = record ['type' ]
118
+ record_type = record ['type' ]
119
119
data = record ['data' ]
120
120
data ['date' ] = record ['date' ]
121
121
data ['received_time' ] = firestore .SERVER_TIMESTAMP
122
122
123
123
if verbose :
124
- print (f'Adding data for { collection = } : { data } ' )
124
+ print (f'Adding data for { record_type = } : { data } ' )
125
125
126
- # Update the main "current" record for the unit .
127
- unit_metadata_ref .set ({collection : data }, merge = True )
126
+ # Update the unit's metadata with the record_type .
127
+ unit_ref .set ({'metadata' : { record_type : data } }, merge = True )
128
128
129
- # Add the record, storing the collection name in the data.
130
- data ['collection ' ] = collection
129
+ # Add the record, storing the record_type name in the data.
130
+ data ['record_type ' ] = record_type
131
131
doc_ts , doc_id = metadata_records_ref .add (data )
132
132
if verbose :
133
133
print (f'Added data to firestore with { doc_id .id = } at { doc_ts } ' )
0 commit comments