shishi6shu/backend/database/3.py
2024-08-23 11:01:27 +00:00

24 lines
927 B
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import subprocess
def run_service():
# 激活虚拟环境并运行服务
# 注意这里的命令被组合成了一个bash脚本字符串
# 首先激活虚拟环境然后改变目录最后执行alembic命令
bash_cmd = f"""
source /home/lqs1/app/venv/bin/activate && \
cd /home/lqs1/app/backend/database && \
alembic revision -m "Add shuai column"
"""
# 使用 Popen 执行bash命令
# 注意这里使用shell=True因为我们正在执行一个bash脚本
# executable='/bin/bash' 是可选的因为默认就是bash但明确指出也无妨
subprocess.Popen(bash_cmd, shell=True, executable='/bin/bash')
if __name__ == '__main__':
run_service()
# alembic revision --autogenerate -m "Add is_superuser column to admin table2" && \
# alembic revision -m "Initial migration" --autogenerate && \
# alembic upgrade head