Skip to content

Commit

Permalink
Working on script executions
Browse files Browse the repository at this point in the history
  • Loading branch information
wilo087 committed Dec 2, 2020
1 parent 85e73ce commit 34acafb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 50 deletions.
33 changes: 20 additions & 13 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
38 changes: 1 addition & 37 deletions pladmin/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 34acafb

Please sign in to comment.