@@ -22,6 +22,11 @@ def stdOut(message):
2222 print (("[" + time .strftime (
2323 "%m.%d.%Y_%H-%M-%S" ) + "] #########################################################################\n " ))
2424
25+ @staticmethod
26+ def migrationsEnabled (pluginName : str ) -> bool :
27+ pluginHome = '/usr/local/CyberCP/' + pluginName
28+ return os .path .exists (pluginHome + '/enable_migrations' )
29+
2530 ### Functions Related to plugin installation.
2631
2732 @staticmethod
@@ -103,6 +108,17 @@ def staticContent():
103108
104109 os .chdir (currentDir )
105110
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+
106122 @staticmethod
107123 def preInstallScript (pluginName ):
108124 pluginHome = '/usr/local/CyberCP/' + pluginName
@@ -184,6 +200,15 @@ def installPlugin(pluginName):
184200
185201 ##
186202
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+
187212 pluginInstaller .restartGunicorn ()
188213
189214 ##
@@ -251,6 +276,14 @@ def removeInterfaceLink(pluginName):
251276 writeToFile .writelines (items )
252277 writeToFile .close ()
253278
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+
254287 @staticmethod
255288 def removePlugin (pluginName ):
256289 try :
@@ -262,6 +295,15 @@ def removePlugin(pluginName):
262295
263296 ##
264297
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+
265307 pluginInstaller .stdOut ('Removing files..' )
266308 pluginInstaller .removeFiles (pluginName )
267309 pluginInstaller .stdOut ('Files removed..' )
0 commit comments