From 34acafb1bc94c48d14dfd03ac7afde143b1d2d6b Mon Sep 17 00:00:00 2001 From: Wilowayne De La Cruz G Date: Wed, 2 Dec 2020 17:04:55 -0400 Subject: [PATCH] Working on script executions --- cli.py | 33 ++++++++++++++++++++------------- pladmin/database.py | 38 +------------------------------------- 2 files changed, 21 insertions(+), 50 deletions(-) diff --git a/cli.py b/cli.py index 6cca407..c85447c 100755 --- a/cli.py +++ b/cli.py @@ -263,7 +263,6 @@ def wc2db(dry_run, force): print(info, '\n') def migrate(dry_run, types='all'): - print(" << MIGRATIONS >> \n") dba = db.dbConnect(sysDBA=True) # Connection to insert migrations in migration table @@ -279,34 +278,42 @@ def migrate(dry_run, types='all'): types = ['AS','DS'] fScripts = files.listAllScriptsFiles(types) - # for script in fScripts: - # print(script) - - # exit(0) for script_path in fScripts: name = files.getFileName(script_path)[0] - dbScript = db.getMigration(scriptName=name, status="OK", db=dba) + dbScript = db.getMigration(scriptName=name, db=dba) data = {} data['name'] = name data['type'] = name[-2:] + data['status']= "NEW" + data['output']= "-" + + if (dbScript) and dbScript[3] == 'OK': + continue - if not dbScript: + if dbScript: + data['status']= dbScript[3] + data['output']= dbScript[4] + + if not dry_run: # Run the script. This return status (OK or FAIL) and output. data['status'], data['output'] = db.RunSqlScript(script_path, db=dba) - + + # if data['status'] == 'FAIL': + # break # Update status on the insert = db.insertOrUpdateMigration(data, db=dbm) - # Agregar dry-run para ver los scripts a ejecutar. - # Agregar un parametro espesifico para ejecutar un script por su nombre. - infoScript.add_row(data.values()) + # Adding data to console table. + infoScript.add_row(data.values()) - print(infoScript) + if dry_run: + utils.dryRun() + print(" << MIGRATIONS >> \n", infoScript) - # Close db connection + # Close dbm connection dbm.commit() dbm.close() dba.close() diff --git a/pladmin/database.py b/pladmin/database.py index 1a0e983..0b74e4f 100644 --- a/pladmin/database.py +++ b/pladmin/database.py @@ -948,6 +948,7 @@ def getMigration(self, scriptName, status='', db=None): "SELECT * FROM %s.PLADMIN_MIGRATIONS WHERE name = '%s' %s" % (self.db_main_schema, scriptName, status) ) + data = cursor.execute(sql) obj = data.fetchone() @@ -1055,43 +1056,6 @@ def insertOrUpdateMigration(self, data, db): else: return self.insertMigration(data, db) - # def executeScript(self, script_path, db=None): - # """ - # Execute scripts - - # params: - # ------ - # path: path routes of the object on the file system - # db (cx_Oracle.Connection): The database connection - - # return (list) with errors if some package were an error - # """ - # localClose = False - # if not db: - # db = self.dbConnect() - # localClose = True - - # cursor = db.cursor() - # cursor.callproc("dbms_output.enable") - - # opf = open(script_path, "r") - # content = opf.read() - # opf.close() - - # # print(content) - - # # Execute create or replace package - # try: - # cursor.execute(content) - # print(self.dbms_output(cursor)) - # except Exception as e: - # # errors.append(e) - # pass - - # if localClose: - # db.close() - - # return True def dbms_output(self, cursor):