Skip to content

Commit

Permalink
feat: fix repeat to create casbin_sequence for PostgreSQL (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
OutOfEastGate authored Nov 14, 2022
1 parent ab66263 commit c0435fe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/org/casbin/adapter/JDBCBaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ protected void migrate() throws SQLException {
sql = renderActualSql("IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='casbin_rule' and xtype='U') CREATE TABLE casbin_rule(id int NOT NULL primary key identity(1, 1), ptype VARCHAR(100) NOT NULL, v0 VARCHAR(100), v1 VARCHAR(100), v2 VARCHAR(100), v3 VARCHAR(100), v4 VARCHAR(100), v5 VARCHAR(100))");
break;
case "PostgreSQL":
sql = renderActualSql("CREATE SEQUENCE IF NOT EXISTS CASBIN_SEQUENCE START 1;");
sql = renderActualSql("do $$ " +
"BEGIN " +
"IF (select count(*) from information_schema.tables where table_name = 'casbin_rule') = 0 " +
"THEN " +
"CREATE SEQUENCE IF NOT EXISTS CASBIN_SEQUENCE START 1; "+
"END IF; " +
"END; " +
"$$;");
break;
case "H2":
sql = renderActualSql("CREATE TABLE IF NOT EXISTS casbin_rule(id int GENERATED ALWAYS AS IDENTITY 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))");
Expand Down

0 comments on commit c0435fe

Please sign in to comment.