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
0a695ba1
Commit
0a695ba1
authored
Jan 20, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final work on migration, now there is no usage of xorm table sync
parent
afb847ac
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
6 deletions
+37
-6
pkg/services/sqlstore/migrations.go
+18
-0
pkg/services/sqlstore/migrations_test.go
+1
-1
pkg/services/sqlstore/migrator/dialect.go
+5
-0
pkg/services/sqlstore/migrator/mysql_dialect.go
+4
-0
pkg/services/sqlstore/migrator/postgres_dialect.go
+4
-0
pkg/services/sqlstore/migrator/sqlite_dialect.go
+4
-0
pkg/services/sqlstore/sqlstore.go
+1
-5
No files found.
pkg/services/sqlstore/migrations.go
View file @
0a695ba1
...
@@ -8,6 +8,7 @@ func addMigrations(mg *Migrator) {
...
@@ -8,6 +8,7 @@ func addMigrations(mg *Migrator) {
addAccountMigrations
(
mg
)
addAccountMigrations
(
mg
)
addDashboardMigration
(
mg
)
addDashboardMigration
(
mg
)
addDataSourceMigration
(
mg
)
addDataSourceMigration
(
mg
)
addTokenMigrations
(
mg
)
}
}
func
addMigrationLogMigrations
(
mg
*
Migrator
)
{
func
addMigrationLogMigrations
(
mg
*
Migrator
)
{
...
@@ -129,3 +130,20 @@ func addDataSourceMigration(mg *Migrator) {
...
@@ -129,3 +130,20 @@ func addDataSourceMigration(mg *Migrator) {
mg
.
AddMigration
(
"add unique index data_source.account_id_name"
,
new
(
AddIndexMigration
)
.
mg
.
AddMigration
(
"add unique index data_source.account_id_name"
,
new
(
AddIndexMigration
)
.
Table
(
"data_source"
)
.
Columns
(
"account_id"
,
"name"
)
.
Unique
())
Table
(
"data_source"
)
.
Columns
(
"account_id"
,
"name"
)
.
Unique
())
}
}
func
addTokenMigrations
(
mg
*
Migrator
)
{
mg
.
AddMigration
(
"create token table"
,
new
(
AddTableMigration
)
.
Name
(
"token"
)
.
WithColumns
(
&
Column
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
&
Column
{
Name
:
"account_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
&
Column
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"token"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"role"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
&
Column
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
))
//------- indexes ------------------
mg
.
AddMigration
(
"add index token.account_id"
,
new
(
AddIndexMigration
)
.
Table
(
"token"
)
.
Columns
(
"account_id"
))
}
pkg/services/sqlstore/migrations_test.go
View file @
0a695ba1
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
var
indexTypes
=
[]
string
{
"Unknown"
,
"INDEX"
,
"UNIQUE INDEX"
}
var
indexTypes
=
[]
string
{
"Unknown"
,
"INDEX"
,
"UNIQUE INDEX"
}
func
A
TestMigrations
(
t
*
testing
.
T
)
{
func
TestMigrations
(
t
*
testing
.
T
)
{
log
.
NewLogger
(
0
,
"console"
,
`{"level": 0}`
)
log
.
NewLogger
(
0
,
"console"
,
`{"level": 0}`
)
testDBs
:=
[]
sqlutil
.
TestDB
{
testDBs
:=
[]
sqlutil
.
TestDB
{
...
...
pkg/services/sqlstore/migrator/dialect.go
View file @
0a695ba1
...
@@ -15,6 +15,7 @@ type Dialect interface {
...
@@ -15,6 +15,7 @@ type Dialect interface {
EqStr
()
string
EqStr
()
string
ShowCreateNull
()
bool
ShowCreateNull
()
bool
SqlType
(
col
*
Column
)
string
SqlType
(
col
*
Column
)
string
SupportEngine
()
bool
CreateIndexSql
(
tableName
string
,
index
*
Index
)
string
CreateIndexSql
(
tableName
string
,
index
*
Index
)
string
CreateTableSql
(
table
*
Table
)
string
CreateTableSql
(
table
*
Table
)
string
...
@@ -85,6 +86,10 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
...
@@ -85,6 +86,10 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
}
}
sql
=
sql
[
:
len
(
sql
)
-
2
]
+
")"
sql
=
sql
[
:
len
(
sql
)
-
2
]
+
")"
if
b
.
dialect
.
SupportEngine
()
{
sql
+=
" ENGINE=InnoDB DEFAULT CHARSET UTF8 "
}
sql
+=
";"
sql
+=
";"
return
sql
return
sql
}
}
...
...
pkg/services/sqlstore/migrator/mysql_dialect.go
View file @
0a695ba1
...
@@ -13,6 +13,10 @@ func NewMysqlDialect() *Mysql {
...
@@ -13,6 +13,10 @@ func NewMysqlDialect() *Mysql {
return
&
d
return
&
d
}
}
func
(
db
*
Mysql
)
SupportEngine
()
bool
{
return
true
}
func
(
db
*
Mysql
)
Quote
(
name
string
)
string
{
func
(
db
*
Mysql
)
Quote
(
name
string
)
string
{
return
"`"
+
name
+
"`"
return
"`"
+
name
+
"`"
}
}
...
...
pkg/services/sqlstore/migrator/postgres_dialect.go
View file @
0a695ba1
...
@@ -13,6 +13,10 @@ func NewPostgresDialect() *Postgres {
...
@@ -13,6 +13,10 @@ func NewPostgresDialect() *Postgres {
return
&
d
return
&
d
}
}
func
(
db
*
Postgres
)
SupportEngine
()
bool
{
return
false
}
func
(
db
*
Postgres
)
Quote
(
name
string
)
string
{
func
(
db
*
Postgres
)
Quote
(
name
string
)
string
{
return
"
\"
"
+
name
+
"
\"
"
return
"
\"
"
+
name
+
"
\"
"
}
}
...
...
pkg/services/sqlstore/migrator/sqlite_dialect.go
View file @
0a695ba1
...
@@ -11,6 +11,10 @@ func NewSqlite3Dialect() *Sqlite3 {
...
@@ -11,6 +11,10 @@ func NewSqlite3Dialect() *Sqlite3 {
return
&
d
return
&
d
}
}
func
(
db
*
Sqlite3
)
SupportEngine
()
bool
{
return
false
}
func
(
db
*
Sqlite3
)
Quote
(
name
string
)
string
{
func
(
db
*
Sqlite3
)
Quote
(
name
string
)
string
{
return
"`"
+
name
+
"`"
return
"`"
+
name
+
"`"
}
}
...
...
pkg/services/sqlstore/sqlstore.go
View file @
0a695ba1
...
@@ -33,11 +33,6 @@ var (
...
@@ -33,11 +33,6 @@ var (
UseSQLite3
bool
UseSQLite3
bool
)
)
func
init
()
{
tables
=
make
([]
interface
{},
0
)
tables
=
append
(
tables
,
new
(
m
.
Token
))
}
func
EnsureAdminUser
()
{
func
EnsureAdminUser
()
{
adminQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
setting
.
AdminUser
}
adminQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
setting
.
AdminUser
}
...
@@ -78,6 +73,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
...
@@ -78,6 +73,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
dialect
=
migrator
.
NewDialect
(
x
.
DriverName
())
dialect
=
migrator
.
NewDialect
(
x
.
DriverName
())
migrator
:=
migrator
.
NewMigrator
(
x
)
migrator
:=
migrator
.
NewMigrator
(
x
)
migrator
.
LogLevel
=
log
.
INFO
addMigrations
(
migrator
)
addMigrations
(
migrator
)
if
err
:=
migrator
.
Start
();
err
!=
nil
{
if
err
:=
migrator
.
Start
();
err
!=
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