diff --git a/migrations/versions/278bcfb487d3_add_hot_spare_pool.py b/migrations/versions/278bcfb487d3_add_hot_spare_pool.py index 00e0575..3de37a8 100644 --- a/migrations/versions/278bcfb487d3_add_hot_spare_pool.py +++ b/migrations/versions/278bcfb487d3_add_hot_spare_pool.py @@ -16,18 +16,20 @@ depends_on = None def upgrade(): + # Add SQL here 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" + sql = text("""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;""") + elif op.get_context().dialect == 'sqlite': + sql = text(f"""INSERT OR IGNORE INTO pool VALUES ( + -1, 'Hot spares (reserve)', datetime('now'), datetime('now'), NULL, 'hotspare', + CAST(RANDOM() AS TEXT), NULL);""") else: - random_string = "CAST(RANDOM() AS TEXT)" - on_conflict = "" - sql = text(f"""INSERT INTO pool VALUES ( - -1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare', - {random_string}, NULL){on_conflict};""") + raise RuntimeError("Using an unsupported engine, only SQLite or PostgreSQL are supported. " + "You could do this migration manually.") op.execute(sql) - def downgrade(): # SQL to undo the changes sql = text("""DELETE FROM pool WHERE id = -1;""")