4
4
import sys
5
5
import webbrowser
6
6
import argparse
7
+ import importlib .util
7
8
from pathlib import Path
8
9
from typing import Optional
10
+ from pip ._internal .cli .main import main as pip_main
9
11
10
12
from InquirerPy .base .control import Choice
11
13
from InquirerPy .resolver import prompt
12
14
13
15
from robyn .env_populator import load_vars
14
16
from robyn .robyn import get_version
17
+ from robyn .migrate import configure_parser , execute_command
15
18
16
19
from .argument_parser import Config
17
20
from .reloader import create_rust_file , setup_reloader
@@ -52,21 +55,10 @@ def create_robyn_app():
52
55
"default" : Choice ("no-db" , name = "No DB" ),
53
56
"name" : "project_type" ,
54
57
},
55
- {
56
- "type" : "list" ,
57
- "message" : "Need Database Migration? (Y/N)" ,
58
- "choices" : [
59
- Choice ("Y" , name = "Y" ),
60
- Choice ("N" , name = "N" ),
61
- ],
62
- "default" : Choice ("N" , name = "N" ),
63
- "name" : "db_migration" ,
64
- },
65
58
]
66
59
result = prompt (questions = questions )
67
60
project_dir_path = Path (str (result ["directory" ])).resolve ()
68
61
docker = result ["docker" ]
69
- db_migration = result ["db_migration" ]
70
62
project_type = str (result ["project_type" ])
71
63
72
64
final_project_dir_path = (CURRENT_WORKING_DIR / project_dir_path ).resolve ()
@@ -83,34 +75,6 @@ def create_robyn_app():
83
75
if docker == "N" :
84
76
os .remove (f"{ final_project_dir_path } /Dockerfile" )
85
77
86
- # If database migration is needed, install alembic
87
- if db_migration == "Y" :
88
- print ("Installing alembic..." )
89
- try :
90
- # Check if alembic is already installed
91
- import importlib .util
92
- alembic_spec = importlib .util .find_spec ('alembic' )
93
-
94
- if alembic_spec is None :
95
- # Install alembic using pip API
96
- try :
97
- import pip
98
- print ("Installing alembic using pip API..." )
99
- from pip ._internal .cli .main import main as pip_main
100
- pip_main (['install' , 'alembic' , '--quiet' ])
101
- print ("Successfully installed alembic." )
102
- except ImportError :
103
- # If pip API is not available, use subprocess
104
- print ("Installing alembic using subprocess..." )
105
- subprocess .run ([sys .executable , "-m" , "pip" , "install" , "alembic" , "-q" ], check = True ,
106
- stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
107
- print ("Successfully installed alembic." )
108
- else :
109
- print ("Alembic is already installed." )
110
- except (subprocess .CalledProcessError , ImportError ) as e :
111
- print (f"Failed to install alembic: { str (e )} " )
112
- print ("Please install it manually using 'pip install alembic'." )
113
-
114
78
print (f"New Robyn project created in '{ final_project_dir_path } ' " )
115
79
116
80
@@ -143,7 +107,6 @@ def start_app_normally(config: Config):
143
107
144
108
def handle_db_command ():
145
109
"""Handle database migration commands."""
146
- import importlib .util
147
110
alembic_spec = importlib .util .find_spec ("alembic" )
148
111
149
112
if alembic_spec is None :
@@ -153,7 +116,6 @@ def handle_db_command():
153
116
if install_choice == 'y' :
154
117
try :
155
118
try :
156
- from pip ._internal .cli .main import main as pip_main
157
119
print ("Installing alembic..." )
158
120
pip_main (['install' , 'alembic' , '--quiet' ])
159
121
print ("Successfully installed alembic." )
@@ -175,13 +137,6 @@ def handle_db_command():
175
137
print ("Please install alembic manually using 'pip install alembic' before using database commands." )
176
138
sys .exit (1 )
177
139
178
- try :
179
- from robyn .migrate import configure_parser , execute_command
180
- except ImportError as e :
181
- print (f"ERROR: Failed to import migrate module: { str (e )} " )
182
- print ("This might be due to an incomplete installation or a version mismatch." )
183
- print ("Try reinstalling Robyn or updating your dependencies." )
184
- sys .exit (1 )
185
140
parser = argparse .ArgumentParser (
186
141
usage = argparse .SUPPRESS , # omit usage hint
187
142
description = 'Robyn database migration commands.'
0 commit comments