Skip to content

Commit f44c1aa

Browse files
committed
adding bool for init_database function to know if tables have already been created
1 parent 05e206b commit f44c1aa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/opengeodeweb_microservice/database/connection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
scoped_session_registry = None
1212

1313

14-
def init_database(db_path: str = DATABASE_FILENAME) -> None:
14+
def init_database(db_path: str = DATABASE_FILENAME, create_tables: bool = True) -> None:
1515
global engine, session_factory, scoped_session_registry
1616

1717
if engine is None:
@@ -22,8 +22,11 @@ def init_database(db_path: str = DATABASE_FILENAME) -> None:
2222
print(f"Database engine created for {db_path}", flush=True)
2323
session_factory = sessionmaker(bind=engine)
2424
scoped_session_registry = scoped_session(session_factory)
25-
Base.metadata.create_all(engine)
26-
print(f"Database engine created DONE for {db_path}")
25+
if create_tables:
26+
Base.metadata.create_all(engine)
27+
print(f"Database tables created for {db_path}", flush=True)
28+
else:
29+
print(f"Database connected (tables not created) for {db_path}", flush=True)
2730
else:
2831
print(f"Database engine already exists for {db_path}, reusing", flush=True)
2932

0 commit comments

Comments
 (0)