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
e02e6017
Commit
e02e6017
authored
Jan 28, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Began work on user favorites backend support & storage
parent
b25bf363
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletions
+64
-1
pkg/models/favorite.go
+17
-0
pkg/services/sqlstore/favorite.go
+34
-0
pkg/services/sqlstore/migrations.go
+13
-1
No files found.
pkg/models/favorite.go
0 → 100644
View file @
e02e6017
package
models
type
Favorite
struct
{
Id
int64
UserId
int64
DashboardId
int64
}
type
AddAsFavoriteCommand
struct
{
UserId
int64
DashboardId
int64
}
type
RemoveAsFavoriteCommand
struct
{
UserId
int64
DashboardId
int64
}
pkg/services/sqlstore/favorite.go
0 → 100644
View file @
e02e6017
package
sqlstore
import
(
"github.com/go-xorm/xorm"
"github.com/torkelo/grafana-pro/pkg/bus"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
AddAsFavorite
)
bus
.
AddHandler
(
"sql"
,
RemoveAsFavorite
)
}
func
AddAsFavorite
(
cmd
*
m
.
AddAsFavoriteCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
entity
:=
m
.
Favorite
{
UserId
:
cmd
.
UserId
,
DashboardId
:
cmd
.
DashboardId
,
}
_
,
err
:=
sess
.
Insert
(
&
entity
)
return
err
})
}
func
RemoveAsFavorite
(
cmd
*
m
.
RemoveAsFavoriteCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM favorite WHERE user_id=? and dashboard_id=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
UserId
,
cmd
.
DashboardId
)
return
err
})
}
pkg/services/sqlstore/migrations.go
View file @
e02e6017
...
...
@@ -6,11 +6,11 @@ import . "github.com/torkelo/grafana-pro/pkg/services/sqlstore/migrator"
// 1. Never change a migration that is committed and pushed to master
// 2. Always add new migrations (to change or undo previous migrations)
// 3. Some migraitons are not yet written (rename column, table, drop table, index etc)
// 4
func
addMigrations
(
mg
*
Migrator
)
{
addMigrationLogMigrations
(
mg
)
addUserMigrations
(
mg
)
addFavoritesMigrations
(
mg
)
addAccountMigrations
(
mg
)
addDashboardMigration
(
mg
)
addDataSourceMigration
(
mg
)
...
...
@@ -55,6 +55,18 @@ func addUserMigrations(mg *Migrator) {
Table
(
"user"
)
.
Column
(
&
Column
{
Name
:
"rands"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
}))
}
func
addFavoritesMigrations
(
mg
*
Migrator
)
{
mg
.
AddMigration
(
"create favorite table"
,
new
(
AddTableMigration
)
.
Name
(
"favorite"
)
.
WithColumns
(
&
Column
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
&
Column
{
Name
:
"user_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
&
Column
{
Name
:
"dashboard_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
))
mg
.
AddMigration
(
"add unique index favorite.user_id_dashboard_id"
,
new
(
AddIndexMigration
)
.
Table
(
"favorite"
)
.
Columns
(
"user_id"
,
"dashboard_id"
)
.
Unique
())
}
func
addAccountMigrations
(
mg
*
Migrator
)
{
mg
.
AddMigration
(
"create account table"
,
new
(
AddTableMigration
)
.
Name
(
"account"
)
.
WithColumns
(
...
...
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