mirror of
https://github.com/usememos/memos.git
synced 2025-02-19 12:50:41 +01:00
chore: simplify find migration history
This commit is contained in:
parent
eacd3e1c17
commit
405fc2b4d2
@ -2,7 +2,6 @@ package mysql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MigrationHistory struct {
|
type MigrationHistory struct {
|
||||||
@ -15,18 +14,11 @@ type MigrationHistoryUpsert struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MigrationHistoryFind struct {
|
type MigrationHistoryFind struct {
|
||||||
Version *string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DB) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {
|
func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *MigrationHistoryFind) ([]*MigrationHistory, error) {
|
||||||
where, args := []string{"1 = 1"}, []any{}
|
query := "SELECT `version`, UNIX_TIMESTAMP(`created_ts`) FROM `migration_history` ORDER BY `created_ts` DESC"
|
||||||
|
rows, err := d.db.QueryContext(ctx, query)
|
||||||
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...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package sqlite
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MigrationHistory struct {
|
type MigrationHistory struct {
|
||||||
@ -15,26 +14,11 @@ type MigrationHistoryUpsert struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MigrationHistoryFind struct {
|
type MigrationHistoryFind struct {
|
||||||
Version *string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DB) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {
|
func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *MigrationHistoryFind) ([]*MigrationHistory, error) {
|
||||||
where, args := []string{"1 = 1"}, []any{}
|
query := "SELECT `version`, `created_ts` FROM `migration_history` ORDER BY `created_ts` DESC"
|
||||||
|
rows, err := d.db.QueryContext(ctx, query)
|
||||||
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...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user