[Concept,03/32] patman: Add upstream and send settings to the database schema

Message ID 20260226200106.1727176-4-sjg@u-boot.org
State New
Headers
Series patman: Add multi-upstream support |

Commit Message

Simon Glass Feb. 26, 2026, 8 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a v5 migration to support per-upstream configuration. This allows
each series to be associated with an upstream remote, each upstream to
have its own patchwork URL and send settings (identity, series_to,
no_maintainers, no_tags) and each series version to have its own
description.

The settings table is recreated without the UNIQUE constraint on
name, since the same patchwork project can be associated with multiple
upstreams.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/patman/database.py     | 38 +++++++++++++++++++++++++++++++++++-
 tools/patman/test_cseries.py |  2 +-
 2 files changed, 38 insertions(+), 2 deletions(-)
  

Patch

diff --git a/tools/patman/database.py b/tools/patman/database.py
index 4557c4ff3fc..2861ca69fa0 100644
--- a/tools/patman/database.py
+++ b/tools/patman/database.py
@@ -19,7 +19,7 @@  from u_boot_pylib import tout
 from patman.series import Series
 
 # Schema version (version 0 means there is no database yet)
-LATEST = 4
+LATEST = 5
 
 # Information about a series/version record
 SerVer = namedtuple(
@@ -156,6 +156,40 @@  class Database:  # pylint:disable=R0904
         """Add an archive tag for each ser_ver"""
         self.cur.execute('ALTER TABLE ser_ver ADD COLUMN archive_tag')
 
+    def _migrate_to_v5(self):
+        """Add upstream support to series, settings and upstream tables
+
+        - Add upstream column to series table
+        - Recreate settings table without UNIQUE constraint on name, adding
+          an upstream column (since the same project can have multiple
+          remotes)
+        - Add patchwork_url, identity, series_to, no_maintainers and
+          no_tags columns to upstream table
+        - Add desc column to ser_ver table
+        """
+        self.cur.execute('ALTER TABLE series ADD COLUMN upstream')
+
+        self.cur.execute(
+            'CREATE TABLE settings_new '
+            '(name, proj_id INT, link_name, upstream)')
+        self.cur.execute(
+            'INSERT INTO settings_new SELECT name, proj_id, link_name, NULL '
+            'FROM settings')
+        self.cur.execute('DROP TABLE settings')
+        self.cur.execute('ALTER TABLE settings_new RENAME TO settings')
+        default_ups = self.upstream_get_default()
+        if default_ups:
+            self.cur.execute(
+                'UPDATE settings SET upstream = ?', (default_ups,))
+
+        self.cur.execute('ALTER TABLE upstream ADD COLUMN patchwork_url')
+        self.cur.execute('ALTER TABLE upstream ADD COLUMN identity')
+        self.cur.execute('ALTER TABLE upstream ADD COLUMN series_to')
+        self.cur.execute(
+            'ALTER TABLE upstream ADD COLUMN no_maintainers BIT')
+        self.cur.execute('ALTER TABLE upstream ADD COLUMN no_tags BIT')
+        self.cur.execute('ALTER TABLE ser_ver ADD COLUMN desc')
+
     def migrate_to(self, dest_version):
         """Migrate the database to the selected version
 
@@ -182,6 +216,8 @@  class Database:  # pylint:disable=R0904
                 self._migrate_to_v3()
             elif version == 4:
                 self._migrate_to_v4()
+            elif version == 5:
+                self._migrate_to_v5()
 
             # Save the new version if we have a schema_version table
             if version > 1:
diff --git a/tools/patman/test_cseries.py b/tools/patman/test_cseries.py
index 3a9411033a6..5719d9b6ddc 100644
--- a/tools/patman/test_cseries.py
+++ b/tools/patman/test_cseries.py
@@ -3316,7 +3316,7 @@  Date:   .*
             self.assertEqual(f'Update database to v{version}',
                              out.getvalue().strip())
             self.assertEqual(version, db.get_schema_version())
-        self.assertEqual(4, database.LATEST)
+        self.assertEqual(5, database.LATEST)
 
     def test_migrate_future_version(self):
         """Test that a database newer than patman is rejected"""