File tree Expand file tree Collapse file tree 3 files changed +8
-26
lines changed
Expand file tree Collapse file tree 3 files changed +8
-26
lines changed Original file line number Diff line number Diff line change 1111
1212from .base import BaseMigrationManager
1313from piccolo import __VERSION__
14- from piccolo .conf .apps import AppConfig , AppRegistry
14+ from piccolo .conf .apps import AppConfig , Finder
1515from piccolo .apps .migrations .auto import (
1616 AlterStatements ,
1717 SchemaSnapshot ,
@@ -149,26 +149,12 @@ def new(app_name: str, auto: bool = False):
149149 """
150150 print ("Creating new migration ..." )
151151
152- try :
153- import piccolo_conf
154- except ImportError :
155- print ("Can't find piccolo_conf" )
156- sys .exit (1 )
157-
158- if auto and isinstance (getattr (piccolo_conf , "DB" ), SQLiteEngine ):
152+ engine = Finder ().get_engine ()
153+ if auto and isinstance (engine , SQLiteEngine ):
159154 print ("Auto migrations aren't currently supported by SQLite." )
160155 sys .exit (1 )
161156
162- try :
163- app_registry : AppRegistry = piccolo_conf .APP_REGISTRY
164- except AttributeError :
165- print ("APP_REGISTRY isn't defined in piccolo_conf" )
166- sys .exit (1 )
167-
168- app_config = app_registry .get_app_config (app_name )
169-
170- if not app_config :
171- raise ValueError (f"Unrecognised app_name: { app_name } " )
157+ app_config = Finder ().get_app_config (app_name = app_name )
172158
173159 _create_migrations_folder (app_config .migrations_folder_path )
174160 _create_new_migration (app_config = app_config , auto = auto )
Original file line number Diff line number Diff line change @@ -28,13 +28,7 @@ def run():
2828 Runs an iPython shell, and automatically imports all of the Table classes
2929 from your project.
3030 """
31- try :
32- import piccolo_conf
33- except ImportError :
34- print ("Can't find piccolo_conf" )
35- sys .exit (1 )
36-
37- app_registry : AppRegistry = piccolo_conf .APP_REGISTRY
31+ app_registry : AppRegistry = Finder ().get_app_registry ()
3832
3933 tables = {}
4034 spacer = "-------"
Original file line number Diff line number Diff line change @@ -295,7 +295,9 @@ def get_app_registry(self) -> AppRegistry:
295295 app_registry = getattr (piccolo_conf_module , "APP_REGISTRY" )
296296 return app_registry
297297
298- def get_engine (self , module_name : t .Optional [str ]) -> t .Optional [Engine ]:
298+ def get_engine (
299+ self , module_name : t .Optional [str ] = None
300+ ) -> t .Optional [Engine ]:
299301 piccolo_conf = self .get_piccolo_conf_module (module_name = module_name )
300302 engine : t .Optional [Engine ] = None
301303 engine = getattr (piccolo_conf , ENGINE_VAR , None )
You can’t perform that action at this time.
0 commit comments