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
f3f79792
Commit
f3f79792
authored
Feb 24, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
account -> org table migration is starting to work, need to test mysql and postgres
parent
ed68a4bb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
90 deletions
+40
-90
pkg/services/sqlstore/migrations/migrations.go
+26
-17
pkg/services/sqlstore/migrations/migrations_test.go
+1
-1
pkg/services/sqlstore/migrations/org_mig.go
+2
-2
pkg/services/sqlstore/migrations/user_mig.go
+4
-13
pkg/services/sqlstore/migrator/migrations.go
+5
-55
pkg/services/sqlstore/org_users.go
+1
-1
pkg/services/sqlstore/user.go
+1
-1
No files found.
pkg/services/sqlstore/migrations/migrations.go
View file @
f3f79792
...
...
@@ -18,25 +18,34 @@ func AddMigrations(mg *Migrator) {
}
func
addMigrationLogMigrations
(
mg
*
Migrator
)
{
mg
.
AddMigration
(
"create migration_log table"
,
new
(
AddTableMigration
)
.
Name
(
"migration_log"
)
.
WithColumns
(
&
Column
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
&
Column
{
Name
:
"migration_id"
,
Type
:
DB_NVarchar
,
Length
:
255
},
&
Column
{
Name
:
"sql"
,
Type
:
DB_Text
},
&
Column
{
Name
:
"success"
,
Type
:
DB_Bool
},
&
Column
{
Name
:
"error"
,
Type
:
DB_Text
},
&
Column
{
Name
:
"timestamp"
,
Type
:
DB_DateTime
},
))
migrationLogV1
:=
Table
{
Name
:
"migration_log"
,
Columns
:
[]
*
Column
{
&
Column
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
&
Column
{
Name
:
"migration_id"
,
Type
:
DB_NVarchar
,
Length
:
255
},
&
Column
{
Name
:
"sql"
,
Type
:
DB_Text
},
&
Column
{
Name
:
"success"
,
Type
:
DB_Bool
},
&
Column
{
Name
:
"error"
,
Type
:
DB_Text
},
&
Column
{
Name
:
"timestamp"
,
Type
:
DB_DateTime
},
},
}
mg
.
AddMigration
(
"create migration_log table"
,
NewAddTableMigration
(
migrationLogV1
))
}
func
addStarMigrations
(
mg
*
Migrator
)
{
mg
.
AddMigration
(
"create star table"
,
new
(
AddTableMigration
)
.
Name
(
"star"
)
.
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
},
))
starV1
:=
Table
{
Name
:
"star"
,
Columns
:
[]
*
Column
{
&
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
},
},
Indices
:
[]
*
Index
{
&
Index
{
Cols
:
[]
string
{
"user_id"
,
"dashboard_id"
},
Type
:
UniqueIndex
},
},
}
mg
.
AddMigration
(
"
add unique index star.user_id_dashboard_id"
,
new
(
AddIndexMigration
)
.
Table
(
"star"
)
.
Columns
(
"user_id"
,
"dashboard_id"
)
.
Unique
(
))
mg
.
AddMigration
(
"
create star table"
,
NewAddTableMigration
(
starV1
))
mg
.
AddMigration
(
"add unique index star.user_id_dashboard_id"
,
NewAddIndexMigration
(
starV1
,
starV1
.
Indices
[
0
]
))
}
pkg/services/sqlstore/migrations/migrations_test.go
View file @
f3f79792
...
...
@@ -32,7 +32,7 @@ func TestMigrations(t *testing.T) {
mg
:=
NewMigrator
(
x
)
mg
.
LogLevel
=
log
.
DEBUG
a
ddMigrations
(
mg
)
A
ddMigrations
(
mg
)
err
=
mg
.
Start
()
So
(
err
,
ShouldBeNil
)
...
...
pkg/services/sqlstore/migrations/org_mig.go
View file @
f3f79792
...
...
@@ -55,7 +55,7 @@ func addOrgMigrations(mg *Migrator) {
"name"
:
"name"
,
"created"
:
"created"
,
"updated"
:
"updated"
,
}))
})
.
IfTableExists
(
"account"
)
)
mg
.
AddMigration
(
"copy data account_user to org_user"
,
NewCopyTableDataMigration
(
"org_user"
,
"account_user"
,
map
[
string
]
string
{
"id"
:
"id"
,
...
...
@@ -64,7 +64,7 @@ func addOrgMigrations(mg *Migrator) {
"role"
:
"role"
,
"created"
:
"created"
,
"updated"
:
"updated"
,
}))
})
.
IfTableExists
(
"account_user"
)
)
mg
.
AddMigration
(
"Drop old table account"
,
NewDropTableMigration
(
"account"
))
mg
.
AddMigration
(
"Drop old table account_user"
,
NewDropTableMigration
(
"account_user"
))
...
...
pkg/services/sqlstore/migrations/user_mig.go
View file @
f3f79792
...
...
@@ -26,20 +26,11 @@ func addUserMigrations(mg *Migrator) {
},
}
// create table
mg
.
AddMigration
(
"create user table"
,
NewAddTableMigration
(
userV1
))
mg
.
AddMigration
(
"Add email_verified flag"
,
new
(
AddColumnMigration
)
.
Table
(
"user"
)
.
Column
(
&
Column
{
Name
:
"email_verified"
,
Type
:
DB_Bool
,
Nullable
:
true
}))
mg
.
AddMigration
(
"Add user.theme column"
,
new
(
AddColumnMigration
)
.
Table
(
"user"
)
.
Column
(
&
Column
{
Name
:
"theme"
,
Type
:
DB_Varchar
,
Nullable
:
true
,
Length
:
20
}))
//------- user table indexes ------------------
mg
.
AddMigration
(
"add unique index user.login"
,
new
(
AddIndexMigration
)
.
Table
(
"user"
)
.
Columns
(
"login"
)
.
Unique
())
mg
.
AddMigration
(
"add unique index user.email"
,
new
(
AddIndexMigration
)
.
Table
(
"user"
)
.
Columns
(
"email"
)
.
Unique
())
// add indices
mg
.
AddMigration
(
"add unique index user.login"
,
NewAddIndexMigration
(
userV1
,
userV1
.
Indices
[
0
]))
mg
.
AddMigration
(
"add unique index user.email"
,
NewAddIndexMigration
(
userV1
,
userV1
.
Indices
[
1
]))
// ---------------------
// account -> org changes
...
...
pkg/services/sqlstore/migrator/migrations.go
View file @
f3f79792
...
...
@@ -85,17 +85,6 @@ func (m *AddIndexMigration) Table(tableName string) *AddIndexMigration {
return
m
}
func
(
m
*
AddIndexMigration
)
Unique
()
*
AddIndexMigration
{
m
.
index
.
Type
=
UniqueIndex
return
m
}
func
(
m
*
AddIndexMigration
)
Columns
(
columns
...
string
)
*
AddIndexMigration
{
m
.
index
=
&
Index
{}
m
.
index
.
Cols
=
columns
return
m
}
func
(
m
*
AddIndexMigration
)
Sql
(
dialect
Dialect
)
string
{
return
dialect
.
CreateIndexSql
(
m
.
tableName
,
m
.
index
)
}
...
...
@@ -110,22 +99,6 @@ func NewDropIndexMigration(table Table, index *Index) *DropIndexMigration {
return
&
DropIndexMigration
{
tableName
:
table
.
Name
,
index
:
index
}
}
func
(
m
*
DropIndexMigration
)
Table
(
tableName
string
)
*
DropIndexMigration
{
m
.
tableName
=
tableName
return
m
}
func
(
m
*
DropIndexMigration
)
Unique
()
*
DropIndexMigration
{
m
.
index
.
Type
=
UniqueIndex
return
m
}
func
(
m
*
DropIndexMigration
)
Columns
(
columns
...
string
)
*
DropIndexMigration
{
m
.
index
=
&
Index
{}
m
.
index
.
Cols
=
columns
return
m
}
func
(
m
*
DropIndexMigration
)
Sql
(
dialect
Dialect
)
string
{
if
m
.
index
.
Name
==
""
{
m
.
index
.
Name
=
fmt
.
Sprintf
(
"%s"
,
strings
.
Join
(
m
.
index
.
Cols
,
"_"
))
...
...
@@ -139,39 +112,16 @@ type AddTableMigration struct {
}
func
NewAddTableMigration
(
table
Table
)
*
AddTableMigration
{
return
&
AddTableMigration
{
table
:
table
}
}
func
(
m
*
AddTableMigration
)
Sql
(
d
Dialect
)
string
{
return
d
.
CreateTableSql
(
&
m
.
table
)
}
func
(
m
*
AddTableMigration
)
Table
(
table
Table
)
*
AddTableMigration
{
m
.
table
=
table
return
m
}
func
(
m
*
AddTableMigration
)
Name
(
name
string
)
*
AddTableMigration
{
m
.
table
.
Name
=
name
return
m
}
func
(
m
*
AddTableMigration
)
WithColumns
(
columns
...*
Column
)
*
AddTableMigration
{
for
_
,
col
:=
range
columns
{
m
.
table
.
Columns
=
append
(
m
.
table
.
Columns
,
col
)
for
_
,
col
:=
range
table
.
Columns
{
if
col
.
IsPrimaryKey
{
m
.
table
.
PrimaryKeys
=
append
(
m
.
table
.
PrimaryKeys
,
col
.
Name
)
table
.
PrimaryKeys
=
append
(
table
.
PrimaryKeys
,
col
.
Name
)
}
}
return
m
return
&
AddTableMigration
{
table
:
table
}
}
func
(
m
*
AddTableMigration
)
WithColumn
(
col
*
Column
)
*
AddTableMigration
{
m
.
table
.
Columns
=
append
(
m
.
table
.
Columns
,
col
)
if
col
.
IsPrimaryKey
{
m
.
table
.
PrimaryKeys
=
append
(
m
.
table
.
PrimaryKeys
,
col
.
Name
)
}
return
m
func
(
m
*
AddTableMigration
)
Sql
(
d
Dialect
)
string
{
return
d
.
CreateTableSql
(
&
m
.
table
)
}
type
DropTableMigration
struct
{
...
...
pkg/services/sqlstore/org_users.go
View file @
f3f79792
...
...
@@ -35,7 +35,7 @@ func AddOrgUser(cmd *m.AddOrgUserCommand) error {
func
GetOrgUsers
(
query
*
m
.
GetOrgUsersQuery
)
error
{
query
.
Result
=
make
([]
*
m
.
OrgUserDTO
,
0
)
sess
:=
x
.
Table
(
"org_user"
)
sess
.
Join
(
"INNER"
,
"user"
,
fmt
.
Sprintf
(
"
account
_user.user_id=%s.id"
,
x
.
Dialect
()
.
Quote
(
"user"
)))
sess
.
Join
(
"INNER"
,
"user"
,
fmt
.
Sprintf
(
"
org
_user.user_id=%s.id"
,
x
.
Dialect
()
.
Quote
(
"user"
)))
sess
.
Where
(
"org_user.org_id=?"
,
query
.
OrgId
)
sess
.
Cols
(
"org_user.org_id"
,
"org_user.user_id"
,
"user.email"
,
"user.login"
,
"org_user.role"
)
sess
.
Asc
(
"user.email"
,
"user.login"
)
...
...
pkg/services/sqlstore/user.go
View file @
f3f79792
...
...
@@ -234,7 +234,7 @@ func GetUserOrgList(query *m.GetUserOrgListQuery) error {
sess
:=
x
.
Table
(
"org_user"
)
sess
.
Join
(
"INNER"
,
"org"
,
"org_user.org_id=org.id"
)
sess
.
Where
(
"org_user.user_id=?"
,
query
.
UserId
)
sess
.
Cols
(
"org.name"
,
"org_user.role"
,
"org_user.
account
_id"
)
sess
.
Cols
(
"org.name"
,
"org_user.role"
,
"org_user.
org
_id"
)
err
:=
sess
.
Find
(
&
query
.
Result
)
return
err
}
...
...
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