Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e6d09b32
Commit
e6d09b32
authored
Aug 12, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(db): remove stars and tags when removing user or dashboard, fixes #2016
parent
8fcaa499
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
13 deletions
+37
-13
pkg/services/sqlstore/dashboard.go
+22
-5
pkg/services/sqlstore/org.go
+2
-4
pkg/services/sqlstore/user.go
+13
-4
No files found.
pkg/services/sqlstore/dashboard.go
View file @
e6d09b32
...
@@ -198,11 +198,28 @@ func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
...
@@ -198,11 +198,28 @@ func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
}
}
func
DeleteDashboard
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
func
DeleteDashboard
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
sess
:=
x
.
NewSession
()
return
inTransaction2
(
func
(
sess
*
session
)
error
{
defer
sess
.
Close
()
dashboard
:=
m
.
Dashboard
{
Slug
:
cmd
.
Slug
,
OrgId
:
cmd
.
OrgId
}
has
,
err
:=
x
.
Get
(
&
dashboard
)
if
err
!=
nil
{
return
err
}
else
if
has
==
false
{
return
m
.
ErrDashboardNotFound
}
rawSql
:=
"DELETE FROM dashboard WHERE org_id=? and slug=?"
deletes
:=
[]
string
{
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
OrgId
,
cmd
.
Slug
)
"DELETE FROM dashboard_tag WHERE dashboard_id = ? "
,
"DELETE FROM star WHERE dashboard_id = ? "
,
"DELETE FROM dashboard WHERE id = ?"
,
}
return
err
for
_
,
sql
:=
range
deletes
{
_
,
err
:=
sess
.
Exec
(
sql
,
dashboard
.
Id
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
}
}
pkg/services/sqlstore/org.go
View file @
e6d09b32
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
)
)
...
@@ -123,8 +122,8 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
...
@@ -123,8 +122,8 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
return
inTransaction2
(
func
(
sess
*
session
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
deletes
:=
[]
string
{
deletes
:=
[]
string
{
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?)"
,
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?
AND star.dashboard_id = dashboard.id
)"
,
"DELETE FROM dashboard_tag WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?)"
,
"DELETE FROM dashboard_tag WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?
AND dashboard_tag.dashboard_id = dashboard.id
)"
,
"DELETE FROM dashboard WHERE org_id = ?"
,
"DELETE FROM dashboard WHERE org_id = ?"
,
"DELETE FROM api_key WHERE org_id = ?"
,
"DELETE FROM api_key WHERE org_id = ?"
,
"DELETE FROM data_source WHERE org_id = ?"
,
"DELETE FROM data_source WHERE org_id = ?"
,
...
@@ -134,7 +133,6 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
...
@@ -134,7 +133,6 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
}
}
for
_
,
sql
:=
range
deletes
{
for
_
,
sql
:=
range
deletes
{
log
.
Trace
(
sql
)
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
Id
)
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/services/sqlstore/user.go
View file @
e6d09b32
package
sqlstore
package
sqlstore
import
(
import
(
"fmt"
"strings"
"strings"
"time"
"time"
...
@@ -309,9 +308,19 @@ func SearchUsers(query *m.SearchUsersQuery) error {
...
@@ -309,9 +308,19 @@ func SearchUsers(query *m.SearchUsersQuery) error {
func
DeleteUser
(
cmd
*
m
.
DeleteUserCommand
)
error
{
func
DeleteUser
(
cmd
*
m
.
DeleteUserCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
fmt
.
Sprintf
(
"DELETE FROM %s WHERE id=?"
,
x
.
Dialect
()
.
Quote
(
"user"
))
deletes
:=
[]
string
{
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
UserId
)
"DELETE FROM star WHERE user_id = ?"
,
return
err
"DELETE FROM user WHERE id = ?"
,
}
for
_
,
sql
:=
range
deletes
{
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
UserId
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment