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
405fc2b4
Commit
405fc2b4
authored
Nov 05, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: simplify find migration history
parent
eacd3e1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
30 deletions
+6
-30
migration_history.go
store/db/mysql/migration_history.go
+3
-11
migration_history.go
store/db/sqlite/migration_history.go
+3
-19
No files found.
store/db/mysql/migration_history.go
View file @
405fc2b4
...
...
@@ -2,7 +2,6 @@ package mysql
import
(
"context"
"strings"
)
type
MigrationHistory
struct
{
...
...
@@ -15,18 +14,11 @@ type MigrationHistoryUpsert struct {
}
type
MigrationHistoryFind
struct
{
Version
*
string
}
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
find
*
MigrationHistoryFind
)
([]
*
MigrationHistory
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
v
:=
find
.
Version
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`version` = ?"
),
append
(
args
,
*
v
)
}
query
:=
"SELECT `version`, UNIX_TIMESTAMP(`created_ts`) FROM `migration_history` WHERE "
+
strings
.
Join
(
where
,
" AND "
)
+
" ORDER BY `created_ts` DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
_
*
MigrationHistoryFind
)
([]
*
MigrationHistory
,
error
)
{
query
:=
"SELECT `version`, UNIX_TIMESTAMP(`created_ts`) FROM `migration_history` ORDER BY `created_ts` DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
store/db/sqlite/migration_history.go
View file @
405fc2b4
...
...
@@ -2,7 +2,6 @@ package sqlite
import
(
"context"
"strings"
)
type
MigrationHistory
struct
{
...
...
@@ -15,26 +14,11 @@ type MigrationHistoryUpsert struct {
}
type
MigrationHistoryFind
struct
{
Version
*
string
}
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
find
*
MigrationHistoryFind
)
([]
*
MigrationHistory
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
v
:=
find
.
Version
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"version = ?"
),
append
(
args
,
*
v
)
}
query
:=
`
SELECT
version,
created_ts
FROM
migration_history
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
+
`
ORDER BY created_ts DESC
`
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
_
*
MigrationHistoryFind
)
([]
*
MigrationHistory
,
error
)
{
query
:=
"SELECT `version`, `created_ts` FROM `migration_history` ORDER BY `created_ts` DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
)
if
err
!=
nil
{
return
nil
,
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