5454from dipdup .utils import pascal_to_snake
5555from dipdup .utils import snake_to_pascal
5656
57- ENV_VARIABLE_REGEX = r'\${([\w]*):-(.*)}'
57+ ENV_VARIABLE_REGEX = r'\${([\w]*):-(.*)}' # ${VARIABLE:-default}
5858DEFAULT_RETRY_COUNT = 3
5959DEFAULT_RETRY_SLEEP = 1
6060DEFAULT_METADATA_URL = 'https://metadata.dipdup.net'
6161DEFAULT_IPFS_URL = 'https://ipfs.io/ipfs'
62+ DEFAULT_POSTGRES_SCHEMA = 'public'
63+ DEFAULT_POSTGRES_USER = DEFAULT_POSTGRES_DATABASE = 'postgres'
64+ DEFAULT_POSTGRES_PORT = 5432
65+ DEFAULT_SQLITE_PATH = ':memory'
6266
6367_logger = logging .getLogger ('dipdup.config' )
6468
@@ -73,7 +77,7 @@ class SqliteDatabaseConfig:
7377 """
7478
7579 kind : Literal ['sqlite' ]
76- path : str = ':memory:'
80+ path : str = DEFAULT_SQLITE_PATH
7781
7882 @cached_property
7983 def connection_string (self ) -> str :
@@ -97,10 +101,10 @@ class PostgresDatabaseConfig:
97101
98102 kind : Literal ['postgres' ]
99103 host : str
100- user : str = 'postgres'
101- database : str = 'postgres'
102- port : int = 5432
103- schema_name : str = 'public'
104+ user : str = DEFAULT_POSTGRES_USER
105+ database : str = DEFAULT_POSTGRES_DATABASE
106+ port : int = DEFAULT_POSTGRES_PORT
107+ schema_name : str = DEFAULT_POSTGRES_SCHEMA
104108 password : str = ''
105109 immune_tables : Tuple [str , ...] = field (default_factory = tuple )
106110 connection_timeout : int = 60
@@ -109,7 +113,10 @@ class PostgresDatabaseConfig:
109113 def connection_string (self ) -> str :
110114 # NOTE: `maxsize=1` is important! Concurrency will be broken otherwise.
111115 # NOTE: https://github.com/tortoise/tortoise-orm/issues/792
112- return f'{ self .kind } ://{ self .user } :{ self .password } @{ self .host } :{ self .port } /{ self .database } ?schema={ self .schema_name } &maxsize=1'
116+ connection_string = f'{ self .kind } ://{ self .user } :{ self .password } @{ self .host } :{ self .port } /{ self .database } ?maxsize=1'
117+ if self .schema_name != DEFAULT_POSTGRES_SCHEMA :
118+ connection_string += f'&schema={ self .schema_name } '
119+ return connection_string
113120
114121 @validator ('immune_tables' )
115122 def valid_immune_tables (cls , v ):
@@ -1009,7 +1016,10 @@ def __post_init_post_parse__(self):
10091016
10101017 @cached_property
10111018 def schema_name (self ) -> str :
1012- return self .database .schema_name if isinstance (self .database , PostgresDatabaseConfig ) else 'public'
1019+ if isinstance (self .database , PostgresDatabaseConfig ):
1020+ return self .database .schema_name
1021+ # NOTE: Not exactly correct; historical reason
1022+ return DEFAULT_POSTGRES_SCHEMA
10131023
10141024 @cached_property
10151025 def package_path (self ) -> str :
0 commit comments