add backend source code

This commit is contained in:
2026-02-28 15:06:52 +08:00
parent 1bc330e20c
commit 2c37aa9064
67 changed files with 11654 additions and 0 deletions

31
backend/rebuild_db.py Normal file
View File

@@ -0,0 +1,31 @@
"""重建数据库"""
import asyncio
import asyncpg
async def main():
# 连接到 postgres 数据库
conn = await asyncpg.connect(
'postgresql://postgresql:Jchl1528@192.168.110.252:15432/postgres'
)
try:
# 终止所有连接
await conn.execute("""
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'hospital_performance' AND pid <> pg_backend_pid()
""")
# 删除数据库
await conn.execute('DROP DATABASE IF EXISTS hospital_performance')
print('数据库已删除')
# 重新创建
await conn.execute('CREATE DATABASE hospital_performance')
print('数据库已创建')
finally:
conn.terminate()
if __name__ == '__main__':
asyncio.run(main())