mirror of
https://github.com/usememos/memos.git
synced 2024-11-15 11:17:58 +08:00
40 lines
660 B
Go
40 lines
660 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
type MigrationHistory struct {
|
|
CreatedTs int64
|
|
Version string
|
|
}
|
|
|
|
func upsertMigrationHistory(db *sql.DB, version string) (*MigrationHistory, error) {
|
|
row, err := db.Query(`
|
|
INSERT INTO migration_history (
|
|
version
|
|
)
|
|
VALUES (?)
|
|
ON CONFLICT(version) DO UPDATE
|
|
SET
|
|
version=EXCLUDED.version
|
|
RETURNING version, created_ts
|
|
`,
|
|
version,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer row.Close()
|
|
|
|
row.Next()
|
|
migrationHistory := MigrationHistory{}
|
|
if err := row.Scan(
|
|
&migrationHistory.Version,
|
|
&migrationHistory.CreatedTs,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &migrationHistory, nil
|
|
}
|