From 9ee4672036e7cba88eb431559f35959b470281ef Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Tue, 9 Jan 2024 22:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/genSQL.groovy | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/script/genSQL.groovy b/script/genSQL.groovy index ac92a882..b051012c 100644 --- a/script/genSQL.groovy +++ b/script/genSQL.groovy @@ -1,9 +1,22 @@ -def execute = """C:\\Program Files\\PostgreSQL\\15\\bin\\pg_dump.exe -d coal_master -h 127.0.0.1 -p 5432 -U postgres -a --inserts -t t_permission -t t_resource -t t_permission_resources --column-inserts """ +def execute = """D:\\dev\\postgresql-16.1-1\\bin\\pg_dump.exe -d coal_master -h 192.168.59.128 -p 5432 -U postgres -a --inserts -t t_permission -t t_resource -t t_permission_resources --column-inserts """ .execute(["PGPASSWORD=abc@123"], new File("../")) +def bs = new ByteArrayOutputStream() +execute.consumeProcessErrorStream(bs) -def insertSQL = execute.text.split("\n").findAll { it.startsWith("INSERT") }.collect {it.replace("INSERT INTO public.", "INSERT INTO ")} + +def insertSQL = execute.text.split("\n").findAll { it.startsWith("INSERT") }.collect { it.replace("INSERT INTO public.", "INSERT INTO ") } + +if (execute.exitValue() != 0) { + + println(new String(bs.toByteArray(), "GBK")) + throw new Exception("execute.exitValue()!=0")} + + +if (insertSQL.size() < 10) { + throw new Exception("insertSQL.size() < 10") +} insertSQL.add(0, """ truncate table t_permission; @@ -17,4 +30,4 @@ truncate table t_resource; def lastVersion = new File("../src/main/resources/db/migration/").listFiles().findAll { it.name.matches("V\\d+__.+") }.collect { it.name.split("_")[0].substring(1).toInteger() }.sort().last() -(new File("../src/main/resources/db/migration/V${lastVersion+1}__resourceAll.sql")).text = insertSQL.join("\n") \ No newline at end of file +(new File("../src/main/resources/db/migration/V${lastVersion + 1}__resourceAll.sql")).text = insertSQL.join("\n") \ No newline at end of file