Skip to content

Commit

Permalink
fix: replace all table names
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored May 7, 2024
1 parent ab5fd74 commit 92d7958
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ func RunMigrations(db *gorm.DB) error {
return err
}

query := db.Raw("SELECT A.user_id, A.team_id, C.scope as permission FROM " + db.Config.NamingStrategy.TableName("user_roles") + " AS A LEFT JOIN role_permissions AS B ON A.role_id = B.role_id LEFT JOIN permissions AS C on B.permission_id = C.id;")
userRolesTableName := db.Config.NamingStrategy.TableName("user_roles")
rolePermissionsTableName := db.Config.NamingStrategy.TableName("role_permissions")
permissionsTableName := db.Config.NamingStrategy.TableName("permissions")

query := db.Raw("SELECT A.user_id, A.team_id, C.scope as permission FROM " + userRolesTableName + " AS A LEFT JOIN " + rolePermissionsTableName + " AS B ON A.role_id = B.role_id LEFT JOIN " + permissionsTableName + " AS C on B.permission_id = C.id;")
err = db.Migrator().CreateView("vw_user_team_permissions", gorm.ViewOption{Query: query, Replace: true})
if err != nil {
return err
}

query = db.Raw("SELECT A.key_id, A.team_id, C.scope as permission FROM " + db.Config.NamingStrategy.TableName("api_key_roles") + " AS A LEFT JOIN role_permissions AS B ON A.role_id = B.role_id LEFT JOIN permissions AS C on B.permission_id = C.id;")
query = db.Raw("SELECT A.key_id, A.team_id, C.scope as permission FROM " + userRolesTableName + " AS A LEFT JOIN " + rolePermissionsTableName + " AS B ON A.role_id = B.role_id LEFT JOIN " + permissionsTableName + " AS C on B.permission_id = C.id;")
err = db.Migrator().CreateView("vw_api_key_team_permissions", gorm.ViewOption{Query: query, Replace: true})
if err != nil {
return err
Expand Down

0 comments on commit 92d7958

Please sign in to comment.