@@ -97,37 +97,12 @@ def cached_text(query: str) -> TextClause:
9797 return text (query )
9898
9999
100- async def reset_db (* , reset_max_users : int = 3 ):
101- from sqlmodel import func , select
102-
103- from owl .db .models import User
104-
100+ async def reset_db ():
105101 # Only allow DB reset in dev with localhost
106102 if "@localhost:" not in ENV_CONFIG .db_path :
107103 raise ValueError ("DB reset is only allowed in dev with localhost DB." )
108104
109105 async with async_session () as session :
110- # As a safety measure, reset DB only if it has less than `init_max_users` users
111- # Just in case we accidentally tried to nuke a prod DB
112- user_table_exists = (
113- await session .exec (
114- text (
115- (
116- f"SELECT EXISTS ("
117- f"SELECT FROM information_schema.tables WHERE table_schema = '{ SCHEMA } ' AND table_name = 'User'"
118- ");"
119- )
120- )
121- )
122- ).scalar ()
123- if user_table_exists :
124- user_count = (await session .exec (select (func .count (User .id )))).one ()
125- if user_count >= reset_max_users :
126- logger .info (
127- f"Found { user_count :,d} users, abort database reset (>= { reset_max_users } users)."
128- )
129- return
130-
131106 # Delete all tables
132107 logger .warning (f'Resetting database (dropping schema "{ SCHEMA } ")...' )
133108 await session .exec (text (f"DROP SCHEMA IF EXISTS { SCHEMA } CASCADE" ))
@@ -702,7 +677,7 @@ async def migrate_db():
702677 await CACHE .aclose ()
703678
704679
705- async def init_db (* , init_max_users : int = 3 ):
680+ async def init_db ():
706681 from fastapi import Request
707682 from sqlmodel import func , select
708683 from starlette .datastructures import URL , Headers
@@ -721,19 +696,16 @@ async def init_db(*, init_max_users: int = 3):
721696 )
722697
723698 async with async_session () as session :
724- # As a safety measure, init DB only if it has less than `init_max_users` users
725- # Just in case we accidentally tried to nuke a prod DB
726699 user_count = (await session .exec (select (func .count (User .id )))).one ()
727- if user_count >= init_max_users :
728- logger .info (
729- f"Found { user_count :,d} users, abort database initialisation (>= { init_max_users } users)."
730- )
731- return
732-
733700 # Only enforce OSS check if db_init=False
734- if ENV_CONFIG .is_oss and user_count != 0 :
735- logger .info ("OSS mode: Skipping initialization (non-empty DB)." )
736- return
701+ if ENV_CONFIG .is_oss :
702+ if user_count != 0 :
703+ logger .info ("OSS mode: Skipping initialization (non-empty DB)." )
704+ return
705+ else :
706+ # Only allow DB init in dev with localhost
707+ if "@localhost:" not in ENV_CONFIG .db_path :
708+ raise ValueError ("DB init is only allowed in dev with localhost DB." )
737709
738710 logger .info ("Initialising database..." )
739711
0 commit comments