[Git][qa/jenkins.debian.net][master] 2 commits: rb: db: wrap some long lines

Mattia Rizzolo (@mattia) gitlab at salsa.debian.org
Wed Aug 13 12:46:13 BST 2025



Mattia Rizzolo pushed to branch master at Debian QA / jenkins.debian.net


Commits:
8d7c0c9b by Mattia Rizzolo at 2025-08-13T13:43:39+02:00
rb: db: wrap some long lines

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
b3eeb427 by Mattia Rizzolo at 2025-08-13T13:43:58+02:00
rb: db: adapt for sqla 2.0

also no need to use sessions in this simple case

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -


1 changed file:

- bin/reproducible_db_maintenance.py


Changes:

=====================================
bin/reproducible_db_maintenance.py
=====================================
@@ -1,9 +1,10 @@
 #!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
-# Copyright © 2015-2018 Mattia Rizzolo <mattia at mapreri.org>
+# Copyright © 2015-2025 Mattia Rizzolo <mattia at mapreri.org>
 # Copyright © 2015-2022 Holger Levsen <holger at layer-acht.org>
-# Based on various reproducible_* files © 2014-2015 Holger Levsen <holger at layer-acht.org>
+# Based on various reproducible_* files
+# © 2014-2015 Holger Levsen <holger at layer-acht.org>
 # Licensed under GPL-2
 #
 # Depends: python3
@@ -14,11 +15,11 @@
 import re
 import sys
 from datetime import datetime
-from sqlalchemy.orm import sessionmaker
+from sqlalchemy import text
 
 from rblib import query_db
 from rblib.confparse import log
-from rblib.const import DB_ENGINE, DB_METADATA
+from rblib.const import DB_METADATA, conn_db
 from rblib.utils import print_critical_message
 
 now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
@@ -194,7 +195,8 @@ schema_updates = {
             save_artifacts INTEGER DEFAULT 0,
             UNIQUE (package_id),
             FOREIGN KEY(package_id) REFERENCES sources(id))''',
-        '''INSERT INTO schedule (package_id, date_scheduled, date_build_started)
+        '''INSERT INTO schedule
+                (package_id, date_scheduled, date_build_started)
            SELECT s.id, p.date_scheduled, p.date_build_started
            FROM sources AS s JOIN sources_scheduled AS p ON s.name = p.name''',
         'DROP TABLE sources_scheduled',
@@ -259,7 +261,7 @@ schema_updates = {
             SELECT datum, suite, reproducible, unreproducible,
             FTBFS, other FROM stats_builds_per_day;''',
         '''DROP TABLE stats_builds_per_day;''',
-        '''ALTER TABLE stats_builds_per_day_tmp RENAME TO stats_builds_per_day;''',
+        'ALTER TABLE stats_builds_per_day_tmp RENAME TO stats_builds_per_day;',
     ],
     6: [  # stats_builds_age needs (datum, suite) as primary key
         '''CREATE TABLE stats_builds_age_tmp
@@ -276,7 +278,8 @@ schema_updates = {
         '''DROP TABLE stats_builds_age;''',
         '''ALTER TABLE stats_builds_age_tmp RENAME TO stats_builds_age;''',
     ],
-    7: [  # change build_duration field in results and stats_build from str to int
+    7: [  # change build_duration field in results
+          # and stats_build from str to int
         '''CREATE TABLE stats_build_tmp
            (id INTEGER PRIMARY KEY,
             name TEXT NOT NULL,
@@ -307,7 +310,8 @@ schema_updates = {
         'DROP TABLE results',
         'ALTER TABLE results_tmp RENAME TO results',
     ],
-    8: [  # add default value to stats_bugs to get a full 'done vs open bugs' graph
+    8: [  # add default value to stats_bugs to get
+          # a full 'done vs open bugs' graph
         '''CREATE TABLE stats_bugs_tmp
            (datum TEXT NOT NULL,
             open_toolchain INTEGER DEFAULT '0',
@@ -366,7 +370,8 @@ schema_updates = {
             url TEXT,
             PRIMARY KEY (name))''',
     ],
-    11: [  # table with removed packages, to enable the maintenance job to do clean up
+    11: [  # table with removed packages, to enable the
+           # maintenance job to do clean up
         '''CREATE TABLE removed_packages (
             name TEXT NOT NULL,
             suite TEXT NOT NULL,
@@ -386,13 +391,15 @@ schema_updates = {
         'ALTER TABLE schedule ADD COLUMN scheduler TEXT',
     ],
     14: [  # column to enable mail notification to maintainers
-        'ALTER TABLE sources ADD COLUMN notify_maintainer INTEGER NOT NULL DEFAULT 0',
+        '''ALTER TABLE sources
+           ADD COLUMN notify_maintainer INTEGER NOT NULL DEFAULT 0''',
     ],
     15: [  # add columns to stats_bugs for new usertag ftbfs
         '''ALTER TABLE stats_bugs ADD COLUMN open_ftbfs INTEGER''',
         '''ALTER TABLE stats_bugs ADD COLUMN done_ftbfs INTEGER''',
     ],
-    16: [  # add default value to stats_bugs.(open|done)_ftbfs to get a full 'done vs open bugs' graph
+    16: [  # add default value to stats_bugs.(open|done)_ftbfs
+           # to get a full 'done vs open bugs' graph
         '''CREATE TABLE stats_bugs_tmp
            (datum TEXT NOT NULL,
             open_toolchain INTEGER DEFAULT '0',
@@ -848,7 +855,6 @@ schema_updates = {
 
 
 def table_exists(tablename):
-    DB_METADATA.reflect(DB_ENGINE)
     if tablename in DB_METADATA.tables:
         return True
     else:
@@ -892,19 +898,18 @@ def db_update():
                                '  the last update available.\nPlease check!')
         sys.exit(1)
     log.info('Found schema updates.')
-    Session = sessionmaker(bind=DB_ENGINE)
-    session = Session()
     for update in range(current+1, last+1):
         log.info('Applying database update #' + str(update) + '. Queries:')
         startTime = datetime.now()
-        with session.begin():
+        with conn_db.begin() as transaction:
             for query in schema_updates[update]:
                 log.info('\t' + query)
-                session.execute(query)
-            session.execute(
+                transaction.execute(text(query))
+            transaction.execute(text(
                 "INSERT INTO rb_schema (version, date) "
                 "VALUES (:ver, CURRENT_TIMESTAMP)", {'ver': update}
-            )
+            ))
+            conn_db.commit()
         log.info(str(len(schema_updates[update])) + ' queries executed in ' +
                  str(datetime.now() - startTime))
     return True



View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/compare/d6c53b1fcd5541cb294104ac5028da6b61eab831...b3eeb4278f0853505b6126a76b9ca7b917cfbd28

-- 
View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/compare/d6c53b1fcd5541cb294104ac5028da6b61eab831...b3eeb4278f0853505b6126a76b9ca7b917cfbd28
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/qa-jenkins-scm/attachments/20250813/906fc603/attachment-0001.htm>


More information about the Qa-jenkins-scm mailing list