Skip to content

Commit

Permalink
fix: if MySQL, check the existence of the table.
Browse files Browse the repository at this point in the history
Signed-off-by: Javakky-pxv <[email protected]>
Javakky-pxv committed Nov 17, 2021
1 parent b7e2d4c commit 868ccc7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/casbin/adapter/JDBCBaseAdapter.java
Original file line number Diff line number Diff line change
@@ -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 " +

0 comments on commit 868ccc7

Please sign in to comment.