Support to copy project

This commit is contained in:
wqy
2022-09-03 08:28:13 +08:00
parent bdb08c6798
commit eaefc61a87
3 changed files with 9 additions and 2 deletions

View File

@@ -9,10 +9,13 @@ def have_project(name: str) -> bool:
cur.execute(f"select * from pg_database where datname = '{name}'")
return cur.rowcount > 0
def create_project(name: str) -> None:
def copy_project(source: str, new: str) -> None:
with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute(f"create database {name} with template = project")
cur.execute(f"create database {new} with template = {source}")
def create_project(name: str) -> None:
return copy_project('project', name)
def delete_project(name: str) -> None:
with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn: