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.
This commit is contained in:
Christian Decker
2021-10-29 13:00:09 +02:00
parent e0745358d1
commit 15b403531e

View File

@@ -35,6 +35,10 @@ class Rewriter(object):
class Sqlite3Rewriter(Rewriter): class Sqlite3Rewriter(Rewriter):
def rewrite_single(self, query): 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 = { typemapping = {
r'BIGINT': 'INTEGER', r'BIGINT': 'INTEGER',
r'BIGINTEGER': 'INTEGER', r'BIGINTEGER': 'INTEGER',
@@ -51,6 +55,10 @@ class Sqlite3Rewriter(Rewriter):
class PostgresRewriter(Rewriter): class PostgresRewriter(Rewriter):
def rewrite_single(self, q): 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 # Let's start by replacing any eventual '?' placeholders
q2 = "" q2 = ""
count = 1 count = 1