From 15b403531e0d40076515e8ae81a33ee21aa58c0e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 29 Oct 2021 13:00:09 +0200 Subject: [PATCH] db: Allow DB-specific queries in the migrations Sometimes we need some DB-specific magic, and marking migrations with `/*PSQL*/` or `/*SQLITE*/` will now give us that. --- devtools/sql-rewrite.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/sql-rewrite.py b/devtools/sql-rewrite.py index 53a861992..4a93a9d9b 100755 --- a/devtools/sql-rewrite.py +++ b/devtools/sql-rewrite.py @@ -35,6 +35,10 @@ class Rewriter(object): class Sqlite3Rewriter(Rewriter): def rewrite_single(self, query): + # Replace DB specific queries with a no-op + if "/*PSQL*/" in query: + return "UPDATE vars SET intval=1 WHERE name='doesnotexist'" # Return a no-op + typemapping = { r'BIGINT': 'INTEGER', r'BIGINTEGER': 'INTEGER', @@ -51,6 +55,10 @@ class Sqlite3Rewriter(Rewriter): class PostgresRewriter(Rewriter): def rewrite_single(self, q): + # Replace DB specific queries with a no-op + if "/*SQLITE*/" in q: + return "UPDATE vars SET intval=1 WHERE name='doesnotexist'" # Return a no-op + # Let's start by replacing any eventual '?' placeholders q2 = "" count = 1