فهرست منبع

cmd_db: use psql tool to create database

- same for create and create-dbonly sub-commands
Daniel-Constantin Mierla 5 سال پیش
والد
کامیت
8d333d7bd1
1فایلهای تغییر یافته به همراه9 افزوده شده و 4 حذف شده
  1. 9 4
      kamcli/commands/cmd_db.py

+ 9 - 4
kamcli/commands/cmd_db.py

@@ -431,11 +431,16 @@ def db_create_mysql(ctx, ldbname, ldirectory, nousers, nogrants, alltables):
 def db_create_postgresql(
 def db_create_postgresql(
     ctx, ldbname, ldirectory, nousers, nogrants, nofunctions, alltables
     ctx, ldbname, ldirectory, nousers, nogrants, nofunctions, alltables
 ):
 ):
+    scmd = (
+        'psql "postgresql://{0}:{1}@{2}" -c "create database {3} "'
+    ).format(
+        ctx.gconfig.get("db", "adminuser"),
+        ctx.gconfig.get("db", "adminpassword"),
+        ctx.gconfig.get("db", "host"),
+        ldbname,
+    )
+    os.system(scmd)
     e = create_engine(ctx.gconfig.get("db", "adminurl"))
     e = create_engine(ctx.gconfig.get("db", "adminurl"))
-    conn = e.connect()
-    conn.connection.connection.set_isolation_level(0)
-    conn.execute("create database {0}".format(ldbname))
-    conn.connection.connection.set_isolation_level(1)
     if not nogrant:
     if not nogrant:
         e.execute(
         e.execute(
             "CREATE USER {0} WITH PASSWORD '{1}';".format(
             "CREATE USER {0} WITH PASSWORD '{1}';".format(