fix(migration): only use on conflict with postgresql

This commit is contained in:
Iain Learmonth 2023-05-31 15:17:39 +01:00
parent 51779b6cc3
commit c013fe72e6

View file

@ -16,10 +16,13 @@ depends_on = None
def upgrade():
# Add SQL here
sql = text("""INSERT INTO pool VALUES (
if op.get_context().dialect.name == 'postgresql':
on_conflict = " ON CONFLICT (id) DO NOTHING"
else:
on_conflict = ""
sql = text(f"""INSERT INTO pool VALUES (
-1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare',
md5(to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS.US')), NULL) ON CONFLICT (id) DO NOTHING;""")
md5(to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS.US')), NULL){on_conflict};""")
op.execute(sql)