Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
525223c2
Commit
525223c2
authored
Aug 26, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add tests for migrator
parent
96b9269c
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
142 additions
and
103 deletions
+142
-103
version.go
server/version/version.go
+0
-5
mysql.go
store/db/mysql/mysql.go
+0
-4
postgres.go
store/db/postgres/postgres.go
+0
-4
sqlite.go
store/db/sqlite/sqlite.go
+0
-4
driver.go
store/driver.go
+0
-4
migrator.go
store/migrator.go
+124
-81
migrator_test.go
test/store/migrator_test.go
+17
-0
test.go
test/test.go
+1
-1
No files found.
server/version/version.go
View file @
525223c2
...
@@ -29,11 +29,6 @@ func GetMinorVersion(version string) string {
...
@@ -29,11 +29,6 @@ func GetMinorVersion(version string) string {
return
versionList
[
0
]
+
"."
+
versionList
[
1
]
return
versionList
[
0
]
+
"."
+
versionList
[
1
]
}
}
func
GetSchemaVersion
(
version
string
)
string
{
minorVersion
:=
GetMinorVersion
(
version
)
return
minorVersion
+
".0"
}
// IsVersionGreaterOrEqualThan returns true if version is greater than or equal to target.
// IsVersionGreaterOrEqualThan returns true if version is greater than or equal to target.
func
IsVersionGreaterOrEqualThan
(
version
,
target
string
)
bool
{
func
IsVersionGreaterOrEqualThan
(
version
,
target
string
)
bool
{
return
semver
.
Compare
(
fmt
.
Sprintf
(
"v%s"
,
version
),
fmt
.
Sprintf
(
"v%s"
,
target
))
>
-
1
return
semver
.
Compare
(
fmt
.
Sprintf
(
"v%s"
,
version
),
fmt
.
Sprintf
(
"v%s"
,
target
))
>
-
1
...
...
store/db/mysql/mysql.go
View file @
525223c2
...
@@ -39,10 +39,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
...
@@ -39,10 +39,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
return
&
driver
,
nil
return
&
driver
,
nil
}
}
func
(
*
DB
)
Type
()
string
{
return
"mysql"
}
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
return
d
.
db
return
d
.
db
}
}
...
...
store/db/postgres/postgres.go
View file @
525223c2
...
@@ -39,10 +39,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
...
@@ -39,10 +39,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
return
driver
,
nil
return
driver
,
nil
}
}
func
(
*
DB
)
Type
()
string
{
return
"postgres"
}
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
return
d
.
db
return
d
.
db
}
}
...
...
store/db/sqlite/sqlite.go
View file @
525223c2
...
@@ -50,10 +50,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
...
@@ -50,10 +50,6 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
return
&
driver
,
nil
return
&
driver
,
nil
}
}
func
(
*
DB
)
Type
()
string
{
return
"sqlite"
}
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
func
(
d
*
DB
)
GetDB
()
*
sql
.
DB
{
return
d
.
db
return
d
.
db
}
}
...
...
store/driver.go
View file @
525223c2
...
@@ -11,10 +11,6 @@ type Driver interface {
...
@@ -11,10 +11,6 @@ type Driver interface {
GetDB
()
*
sql
.
DB
GetDB
()
*
sql
.
DB
Close
()
error
Close
()
error
// Type returns the type of the driver.
// Supported types are: sqlite, mysql, postgres.
Type
()
string
// MigrationHistory model related methods.
// MigrationHistory model related methods.
FindMigrationHistoryList
(
ctx
context
.
Context
,
find
*
FindMigrationHistory
)
([]
*
MigrationHistory
,
error
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
find
*
FindMigrationHistory
)
([]
*
MigrationHistory
,
error
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
UpsertMigrationHistory
)
(
*
MigrationHistory
,
error
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
UpsertMigrationHistory
)
(
*
MigrationHistory
,
error
)
...
...
store/migrator.go
View file @
525223c2
This diff is collapsed.
Click to expand it.
test/store/migrator_test.go
0 → 100644
View file @
525223c2
package
teststore
import
(
"context"
"testing"
"github.com/stretchr/testify/require"
)
func
TestGetCurrentSchemaVersion
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ts
:=
NewTestingStore
(
ctx
,
t
)
currentSchemaVersion
,
err
:=
ts
.
GetCurrentSchemaVersion
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"0.22.4"
,
currentSchemaVersion
)
}
test/test.go
View file @
525223c2
...
@@ -32,7 +32,7 @@ func GetTestingProfile(t *testing.T) *profile.Profile {
...
@@ -32,7 +32,7 @@ func GetTestingProfile(t *testing.T) *profile.Profile {
// Get a temporary directory for the test data.
// Get a temporary directory for the test data.
dir
:=
t
.
TempDir
()
dir
:=
t
.
TempDir
()
mode
:=
"
dev
"
mode
:=
"
prod
"
port
:=
getUnusedPort
()
port
:=
getUnusedPort
()
driver
:=
getDriverFromEnv
()
driver
:=
getDriverFromEnv
()
dsn
:=
os
.
Getenv
(
"DSN"
)
dsn
:=
os
.
Getenv
(
"DSN"
)
...
...
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