From 868ccc73ba6e23066f28eb61ba7393ee80a5996a Mon Sep 17 00:00:00 2001 From: Javakky-pxv Date: Mon, 15 Nov 2021 11:31:32 +0900 Subject: [PATCH] fix: if MySQL, check the existence of the table. Signed-off-by: Javakky-pxv --- src/main/java/org/casbin/adapter/JDBCBaseAdapter.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java index 79c1a34..1f33abd 100644 --- a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java +++ b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java @@ -79,6 +79,13 @@ protected void migrate() throws SQLException { String productName = conn.getMetaData().getDatabaseProductName(); switch (productName) { + case "MySQL": + String hasTableSql = "SHOW TABLES LIKE 'casbin_rule';"; + ResultSet rs = stmt.executeQuery(hasTableSql); + if (rs.next()) { + return; + } + break; case "Oracle": sql = "declare begin execute immediate 'CREATE TABLE CASBIN_RULE(id NUMBER(5, 0) not NULL primary key, ptype VARCHAR(100) not NULL, v0 VARCHAR(100), v1 VARCHAR(100), v2 VARCHAR(100), v3 VARCHAR(100), v4 VARCHAR(100), v5 VARCHAR(100))'; " + "exception when others then " +