fix(migration): just use two different commands
This commit is contained in:
parent
1d7a8ce1a0
commit
f91f7e5274
1 changed files with 10 additions and 8 deletions
|
@ -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"
|
||||
else:
|
||||
random_string = "CAST(RANDOM() AS TEXT)"
|
||||
on_conflict = ""
|
||||
sql = text(f"""INSERT INTO pool VALUES (
|
||||
sql = text("""INSERT INTO pool VALUES (
|
||||
-1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare',
|
||||
{random_string}, NULL){on_conflict};""")
|
||||
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:
|
||||
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;""")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue