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
8bb9126b
Commit
8bb9126b
authored
Jan 20, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added postgres support for db migrations
parent
2379c5b7
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
107 additions
and
15 deletions
+107
-15
conf/grafana.ini
+1
-1
docker/blocks/graphite/fig
+1
-1
docker/blocks/postgres_tests/fig
+7
-0
docker/fig.yml
+8
-0
pkg/services/sqlstore/migrations/migrations_test.go
+1
-0
pkg/services/sqlstore/migrations/migrator.go
+2
-0
pkg/services/sqlstore/migrations/mysql_dialect.go
+1
-13
pkg/services/sqlstore/migrations/postgres_dialect.go
+86
-0
No files found.
conf/grafana.ini
View file @
8bb9126b
...
@@ -84,7 +84,7 @@ mode = console
...
@@ -84,7 +84,7 @@ mode = console
; Buffer length of channel, keep it as it is if you don't know what it is.
; Buffer length of channel, keep it as it is if you don't know what it is.
buffer_len
=
10000
buffer_len
=
10000
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
level
=
Trace
level
=
Info
; For "console" mode only
; For "console" mode only
[log.console]
[log.console]
...
...
docker/blocks/graphite/fig
View file @
8bb9126b
graphite:
graphite:
build: blocks/
docker_
graphite
build: blocks/graphite
ports:
ports:
- "8776:80"
- "8776:80"
docker/blocks/postgres_tests/fig
0 → 100644
View file @
8bb9126b
postgrestest:
image: postgres:latest
environment:
POSTGRES_USER: grafanatest
POSTGRES_PASSWORD: grafanatest
ports:
- "5432:5432"
docker/fig.yml
View file @
8bb9126b
...
@@ -8,3 +8,11 @@ mysqltests:
...
@@ -8,3 +8,11 @@ mysqltests:
ports
:
ports
:
-
"
3306:3306"
-
"
3306:3306"
postgrestest
:
image
:
postgres:latest
environment
:
POSTGRES_USER
:
grafanatest
POSTGRES_PASSWORD
:
grafanatest
ports
:
-
"
5432:5432"
pkg/services/sqlstore/migrations/migrations_test.go
View file @
8bb9126b
...
@@ -35,6 +35,7 @@ func TestMigrations(t *testing.T) {
...
@@ -35,6 +35,7 @@ func TestMigrations(t *testing.T) {
log
.
NewLogger
(
0
,
"console"
,
`{"level": 0}`
)
log
.
NewLogger
(
0
,
"console"
,
`{"level": 0}`
)
testDBs
:=
[][]
string
{
testDBs
:=
[][]
string
{
[]
string
{
"postgres"
,
"user=grafanatest password=grafanatest host=localhost port=5432 dbname=grafanatest sslmode=disable"
},
[]
string
{
"mysql"
,
"grafana:password@tcp(localhost:3306)/grafana_tests?charset=utf8"
},
[]
string
{
"mysql"
,
"grafana:password@tcp(localhost:3306)/grafana_tests?charset=utf8"
},
[]
string
{
"sqlite3"
,
":memory:"
},
[]
string
{
"sqlite3"
,
":memory:"
},
}
}
...
...
pkg/services/sqlstore/migrations/migrator.go
View file @
8bb9126b
...
@@ -38,6 +38,8 @@ func NewMigrator(engine *xorm.Engine) *Migrator {
...
@@ -38,6 +38,8 @@ func NewMigrator(engine *xorm.Engine) *Migrator {
mg
.
dialect
=
NewMysqlDialect
()
mg
.
dialect
=
NewMysqlDialect
()
case
SQLITE
:
case
SQLITE
:
mg
.
dialect
=
NewSqlite3Dialect
()
mg
.
dialect
=
NewSqlite3Dialect
()
case
POSTGRES
:
mg
.
dialect
=
NewPostgresDialect
()
}
}
return
mg
return
mg
...
...
pkg/services/sqlstore/migrations/mysql_dialect.go
View file @
8bb9126b
package
migrations
package
migrations
import
(
import
"strconv"
"fmt"
"strconv"
)
type
Mysql
struct
{
type
Mysql
struct
{
BaseDialect
BaseDialect
...
@@ -71,15 +68,6 @@ func (db *Mysql) SqlType(c *Column) string {
...
@@ -71,15 +68,6 @@ func (db *Mysql) SqlType(c *Column) string {
return
res
return
res
}
}
func
(
db
*
Mysql
)
ToDBTypeSql
(
columnType
ColumnType
,
length
int
)
string
{
switch
columnType
{
case
DB_TYPE_STRING
:
return
fmt
.
Sprintf
(
"NVARCHAR(%d)"
,
length
)
}
panic
(
"Unsupported db type"
)
}
func
(
db
*
Mysql
)
TableCheckSql
(
tableName
string
)
(
string
,
[]
interface
{})
{
func
(
db
*
Mysql
)
TableCheckSql
(
tableName
string
)
(
string
,
[]
interface
{})
{
args
:=
[]
interface
{}{
"grafana"
,
tableName
}
args
:=
[]
interface
{}{
"grafana"
,
tableName
}
sql
:=
"SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
sql
:=
"SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
...
...
pkg/services/sqlstore/migrations/postgres_dialect.go
0 → 100644
View file @
8bb9126b
package
migrations
import
(
"strconv"
"github.com/go-xorm/core"
)
type
Postgres
struct
{
BaseDialect
}
func
NewPostgresDialect
()
*
Postgres
{
d
:=
Postgres
{}
d
.
BaseDialect
.
dialect
=
&
d
d
.
BaseDialect
.
driverName
=
POSTGRES
return
&
d
}
func
(
db
*
Postgres
)
Quote
(
name
string
)
string
{
return
"
\"
"
+
name
+
"
\"
"
}
func
(
db
*
Postgres
)
QuoteStr
()
string
{
return
"
\"
"
}
func
(
db
*
Postgres
)
AutoIncrStr
()
string
{
return
""
}
func
(
db
*
Postgres
)
SqlType
(
c
*
Column
)
string
{
var
res
string
switch
t
:=
c
.
Type
;
t
{
case
DB_TinyInt
:
res
=
DB_SmallInt
return
res
case
DB_MediumInt
,
core
.
Int
,
core
.
Integer
:
if
c
.
IsAutoIncrement
{
return
DB_Serial
}
return
DB_Integer
case
DB_Serial
,
core
.
BigSerial
:
c
.
IsAutoIncrement
=
true
c
.
Nullable
=
false
res
=
t
case
DB_Binary
,
core
.
VarBinary
:
return
DB_Bytea
case
DB_DateTime
:
res
=
DB_TimeStamp
case
DB_TimeStampz
:
return
"timestamp with time zone"
case
DB_Float
:
res
=
DB_Real
case
DB_TinyText
,
core
.
MediumText
,
core
.
LongText
:
res
=
DB_Text
case
DB_NVarchar
:
res
=
DB_Varchar
case
DB_Uuid
:
res
=
DB_Uuid
case
DB_Blob
,
core
.
TinyBlob
,
core
.
MediumBlob
,
core
.
LongBlob
:
return
DB_Bytea
case
DB_Double
:
return
"DOUBLE PRECISION"
default
:
if
c
.
IsAutoIncrement
{
return
DB_Serial
}
res
=
t
}
var
hasLen1
bool
=
(
c
.
Length
>
0
)
var
hasLen2
bool
=
(
c
.
Length2
>
0
)
if
hasLen2
{
res
+=
"("
+
strconv
.
Itoa
(
c
.
Length
)
+
","
+
strconv
.
Itoa
(
c
.
Length2
)
+
")"
}
else
if
hasLen1
{
res
+=
"("
+
strconv
.
Itoa
(
c
.
Length
)
+
")"
}
return
res
}
func
(
db
*
Postgres
)
TableCheckSql
(
tableName
string
)
(
string
,
[]
interface
{})
{
args
:=
[]
interface
{}{
"grafana"
,
tableName
}
sql
:=
"SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
return
sql
,
args
}
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