summaryrefslogtreecommitdiffstats
path: root/bin/reproducible_db_maintenance.py
diff options
context:
space:
mode:
authorMattia Rizzolo <mattia@mapreri.org>2015-03-29 14:18:01 +0200
committerMattia Rizzolo <mattia@mapreri.org>2015-03-29 14:18:01 +0200
commit0eab6faefc17b5fab951485bad7bbc5a363dd56f (patch)
tree991f5dd0b37b10b0a89913129be21561d16617ea /bin/reproducible_db_maintenance.py
parent4a4b2611e30f7d942757770f7a7067309d06e063 (diff)
downloadjenkins.debian.net-0eab6faefc17b5fab951485bad7bbc5a363dd56f.tar.xz
reproducible: db_maintenance: print out execution time infos
Diffstat (limited to 'bin/reproducible_db_maintenance.py')
-rwxr-xr-xbin/reproducible_db_maintenance.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/bin/reproducible_db_maintenance.py b/bin/reproducible_db_maintenance.py
index 3545a238..5b82f5c4 100755
--- a/bin/reproducible_db_maintenance.py
+++ b/bin/reproducible_db_maintenance.py
@@ -15,6 +15,7 @@ from reproducible_common import *
now = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
+
# the original schema is here
db_schema = [
{
@@ -347,6 +348,7 @@ def db_create_tables():
The check is done against sqlite_master, a reserved sqlite table
containing all database metadata.
"""
+ changed = False
for table in db_schema:
query = 'SELECT name FROM sqlite_master WHERE name="{}"'
query = query.format(table['name'])
@@ -355,6 +357,8 @@ def db_create_tables():
for query in table['query']:
log.info('\t' + re.sub(' +', ' ', query.replace('\n', ' ')))
query_db(query)
+ changed = True
+ return changed
def db_update():
@@ -371,7 +375,7 @@ def db_update():
current = 0
last = max(schema_updates.keys())
if current == last:
- return
+ return False
if current > last:
print_critiacal_message('The active database schema is higher than' +
' the last update available.\nPlease check!')
@@ -379,17 +383,27 @@ def db_update():
log.info('Found schema updates.')
for update in range(current+1, last+1):
log.info('Applying database update #' + str(update) + '. Queries:')
+ startTime = datetime.datetime.now()
for query in schema_updates[update]:
log.info('\t' + query)
query_db(query)
+ log.info(str(len(schema_updates[update])) + ' queries executed in ' +
+ str(datetime.datetime.now() - startTime))
+ return True
if __name__ == '__main__':
+ changed_created = False
try:
if not query_db('SELECT * FROM rb_schema'):
- db_create_tables()
+ changed_create = db_create_tables()
except:
log.error('There is no rb_schema table in the database.')
log.error('Will run a full db_create_tables().')
- db_create_tables()
- db_update()
+ changed_created = db_create_tables()
+ changed = db_update()
+ if changed or changed_created:
+ log.info('Total execution time: ' + str(datetime.datetime.now() -
+ datetime.datetime.strptime(now, "%Y-%m-%d-%H-%M-%S")))
+ else:
+ log.info('No pending updates.')