fix(migration): use random() on sqlite

This commit is contained in:
Iain Learmonth 2023-05-31 15:24:08 +01:00
parent c013fe72e6
commit 1d7a8ce1a0

View file

@ -17,12 +17,14 @@ depends_on = None
def upgrade(): def upgrade():
if op.get_context().dialect.name == 'postgresql': if op.get_context().dialect.name == 'postgresql':
random_string = "md5(to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS.US'))"
on_conflict = " ON CONFLICT (id) DO NOTHING" on_conflict = " ON CONFLICT (id) DO NOTHING"
else: else:
random_string = "CAST(RANDOM() AS TEXT)"
on_conflict = "" on_conflict = ""
sql = text(f"""INSERT INTO pool VALUES ( sql = text(f"""INSERT INTO pool VALUES (
-1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare', -1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare',
md5(to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS.US')), NULL){on_conflict};""") {random_string}, NULL){on_conflict};""")
op.execute(sql) op.execute(sql)