@@ -22,6 +22,11 @@ def stdOut(message):
22
22
print (("[" + time .strftime (
23
23
"%m.%d.%Y_%H-%M-%S" ) + "] #########################################################################\n " ))
24
24
25
+ @staticmethod
26
+ def migrationsEnabled (pluginName : str ) -> bool :
27
+ pluginHome = '/usr/local/CyberCP/' + pluginName
28
+ return os .path .exists (pluginHome + '/enable_migrations' )
29
+
25
30
### Functions Related to plugin installation.
26
31
27
32
@staticmethod
@@ -103,6 +108,17 @@ def staticContent():
103
108
104
109
os .chdir (currentDir )
105
110
111
+ @staticmethod
112
+ def installMigrations (pluginName ):
113
+ currentDir = os .getcwd ()
114
+ os .chdir ('/usr/local/CyberCP' )
115
+ command = "/usr/local/CyberCP/bin/python manage.py makemigrations %s" % pluginName
116
+ subprocess .call (shlex .split (command ))
117
+ command = "/usr/local/CyberCP/bin/python manage.py migrate %s" % pluginName
118
+ subprocess .call (shlex .split (command ))
119
+ os .chdir (currentDir )
120
+
121
+
106
122
@staticmethod
107
123
def preInstallScript (pluginName ):
108
124
pluginHome = '/usr/local/CyberCP/' + pluginName
@@ -184,6 +200,15 @@ def installPlugin(pluginName):
184
200
185
201
##
186
202
203
+ if pluginInstaller .migrationsEnabled (pluginName ):
204
+ pluginInstaller .stdOut ('Running Migrations..' )
205
+ pluginInstaller .installMigrations (pluginName )
206
+ pluginInstaller .stdOut ('Migrations Completed..' )
207
+ else :
208
+ pluginInstaller .stdOut ('Migrations not enabled, add file \' enable_migrations\' to plugin to enable' )
209
+
210
+ ##
211
+
187
212
pluginInstaller .restartGunicorn ()
188
213
189
214
##
@@ -251,6 +276,14 @@ def removeInterfaceLink(pluginName):
251
276
writeToFile .writelines (items )
252
277
writeToFile .close ()
253
278
279
+ @staticmethod
280
+ def removeMigrations (pluginName ):
281
+ currentDir = os .getcwd ()
282
+ os .chdir ('/usr/local/CyberCP' )
283
+ command = "/usr/local/CyberCP/bin/python manage.py migrate %s zero" % pluginName
284
+ subprocess .call (shlex .split (command ))
285
+ os .chdir (currentDir )
286
+
254
287
@staticmethod
255
288
def removePlugin (pluginName ):
256
289
try :
@@ -262,6 +295,15 @@ def removePlugin(pluginName):
262
295
263
296
##
264
297
298
+ if pluginInstaller .migrationsEnabled (pluginName ):
299
+ pluginInstaller .stdOut ('Removing migrations..' )
300
+ pluginInstaller .removeMigrations (pluginName )
301
+ pluginInstaller .stdOut ('Migrations removed..' )
302
+ else :
303
+ pluginInstaller .stdOut ('Migrations not enabled, add file \' enable_migrations\' to plugin to enable' )
304
+
305
+ ##
306
+
265
307
pluginInstaller .stdOut ('Removing files..' )
266
308
pluginInstaller .removeFiles (pluginName )
267
309
pluginInstaller .stdOut ('Files removed..' )
0 commit comments