34 lines
923 B
Python
34 lines
923 B
Python
"""Add hot spare pool
|
|
|
|
Revision ID: 278bcfb487d3
|
|
Revises: 2d747ffb9928
|
|
Create Date: 2023-05-30 16:08:37.770371
|
|
|
|
"""
|
|
from alembic import op
|
|
from sqlalchemy.sql import text
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '278bcfb487d3'
|
|
down_revision = '2d747ffb9928'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
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 (
|
|
-1, 'Hot spares (reserve)', NOW(), NOW(), NULL, 'hotspare',
|
|
{random_string}, NULL){on_conflict};""")
|
|
op.execute(sql)
|
|
|
|
|
|
def downgrade():
|
|
# SQL to undo the changes
|
|
sql = text("""DELETE FROM pool WHERE id = -1;""")
|
|
op.execute(sql)
|