Skip to content

Commit 08a5cf2

Browse files
arhowe00ebrahimebrahim
authored andcommitted
Add static Database initialization function (#217)
- Adds an empty database to the specified location with empty tables.
1 parent 148a21c commit 08a5cf2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/openlifu/db/database.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,3 +1075,21 @@ def get_default_path():
10751075
:returns: Default path for the database
10761076
"""
10771077
return Path(Database.get_default_user_dir()) / "Documents" / "db"
1078+
1079+
@staticmethod
1080+
def initialize_empty_database(database_filepath : Path | str) -> None:
1081+
"""
1082+
Initializes an empty database at the given database_filepath
1083+
"""
1084+
database_filepath = Path(database_filepath)
1085+
subdirs = ["protocols", "users", "subjects", "transducers", "systems"]
1086+
for subdir in subdirs:
1087+
(database_filepath / subdir).mkdir(parents=True, exist_ok=True)
1088+
1089+
new_db = Database(str(database_filepath))
1090+
1091+
new_db.write_protocol_ids([])
1092+
new_db.write_user_ids([])
1093+
new_db.write_subject_ids([])
1094+
new_db.write_transducer_ids([])
1095+
#new_db.write_system_ids([])

0 commit comments

Comments
 (0)