feat(build): add Cgo free database
This commit is contained in:
No files matched your search
@@ -26,7 +26,6 @@ import (
|
|||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
|
||||||
"github.com/sentriz/gormstore"
|
"github.com/sentriz/gormstore"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// CGo-free Wasm tagger
|
// Cgo-free Wasm database
|
||||||
|
_ "github.com/ncruces/go-sqlite3/driver"
|
||||||
|
_ "github.com/ncruces/go-sqlite3/embed"
|
||||||
|
|
||||||
|
// Cgo-free Wasm tagger
|
||||||
"go.senan.xyz/gonic/tags/wrtag"
|
"go.senan.xyz/gonic/tags/wrtag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
// Cgo database
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
// Cgo tagger
|
// Cgo tagger
|
||||||
"go.senan.xyz/gonic/tags/taglib"
|
"go.senan.xyz/gonic/tags/taglib"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -13,7 +12,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/mattn/go-sqlite3"
|
|
||||||
|
|
||||||
// TODO: remove this dep
|
// TODO: remove this dep
|
||||||
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
|
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
|
||||||
@@ -43,7 +41,6 @@ type DB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(path string, options url.Values) (*DB, error) {
|
func New(path string, options url.Values) (*DB, error) {
|
||||||
// https://github.com/mattn/go-sqlite3#connection-string
|
|
||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "file",
|
Scheme: "file",
|
||||||
Opaque: path,
|
Opaque: path,
|
||||||
@@ -620,45 +617,3 @@ func join[T fmt.Stringer](in []T, sep string) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(strs, sep)
|
return strings.Join(strs, sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dump(ctx context.Context, db *gorm.DB, to string) error {
|
|
||||||
dest, err := New(to, url.Values{})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("create dest db: %w", err)
|
|
||||||
}
|
|
||||||
defer dest.Close()
|
|
||||||
|
|
||||||
connSrc, err := db.DB().Conn(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting src raw conn: %w", err)
|
|
||||||
}
|
|
||||||
defer connSrc.Close()
|
|
||||||
|
|
||||||
connDest, err := dest.DB.DB().Conn(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting dest raw conn: %w", err)
|
|
||||||
}
|
|
||||||
defer connDest.Close()
|
|
||||||
|
|
||||||
err = connDest.Raw(func(connDest any) error {
|
|
||||||
return connSrc.Raw(func(connSrc any) error {
|
|
||||||
connDestq := connDest.(*sqlite3.SQLiteConn)
|
|
||||||
connSrcq := connSrc.(*sqlite3.SQLiteConn)
|
|
||||||
bk, err := connDestq.Backup("main", connSrcq, "main")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("create backup db: %w", err)
|
|
||||||
}
|
|
||||||
for done, _ := bk.Step(-1); !done; { //nolint: revive
|
|
||||||
}
|
|
||||||
if err := bk.Finish(); err != nil {
|
|
||||||
return fmt.Errorf("finishing dump: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("backing up: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -59,7 +58,6 @@ func (db *DB) Migrate(ctx MigrationContext) error {
|
|||||||
construct(ctx, "202206101425", migrateUser),
|
construct(ctx, "202206101425", migrateUser),
|
||||||
construct(ctx, "202207251148", migrateStarRating),
|
construct(ctx, "202207251148", migrateStarRating),
|
||||||
construct(ctx, "202211111057", migratePlaylistsQueuesToFullID),
|
construct(ctx, "202211111057", migratePlaylistsQueuesToFullID),
|
||||||
constructNoTx(ctx, "202212272312", backupDBPre016),
|
|
||||||
construct(ctx, "202304221528", migratePlaylistsToM3U),
|
construct(ctx, "202304221528", migratePlaylistsToM3U),
|
||||||
construct(ctx, "202305301718", migratePlayCountToLength),
|
construct(ctx, "202305301718", migratePlayCountToLength),
|
||||||
construct(ctx, "202307281628", migrateAlbumArtistsMany2Many),
|
construct(ctx, "202307281628", migrateAlbumArtistsMany2Many),
|
||||||
@@ -738,13 +736,6 @@ func migratePlaylistsPaths(tx *gorm.DB, ctx MigrationContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func backupDBPre016(tx *gorm.DB, ctx MigrationContext) error {
|
|
||||||
if !ctx.Production {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return Dump(context.Background(), tx, fmt.Sprintf("%s.%d.bak", ctx.DBPath, time.Now().Unix()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func migrateAlbumTagArtistString(tx *gorm.DB, _ MigrationContext) error {
|
func migrateAlbumTagArtistString(tx *gorm.DB, _ MigrationContext) error {
|
||||||
return tx.AutoMigrate(Album{}).Error
|
return tx.AutoMigrate(Album{}).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ require (
|
|||||||
github.com/microcosm-cc/bluemonday v1.0.27
|
github.com/microcosm-cc/bluemonday v1.0.27
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/mmcdole/gofeed v1.3.0
|
github.com/mmcdole/gofeed v1.3.0
|
||||||
|
github.com/ncruces/go-sqlite3 v0.29.0
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4
|
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4
|
||||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
|
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
|
||||||
@@ -56,6 +57,7 @@ require (
|
|||||||
github.com/mmcdole/goxpp v1.1.1 // indirect
|
github.com/mmcdole/goxpp v1.1.1 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/ncruces/julianday v1.0.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/tetratelabs/wazero v1.9.0 // indirect
|
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||||
go.senan.xyz/taglib v0.8.0 // indirect
|
go.senan.xyz/taglib v0.8.0 // indirect
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
|||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/ncruces/go-sqlite3 v0.29.0 h1:1tsLiagCoqZEfcHDeKsNSv5jvrY/Iu393pAnw2wLNJU=
|
||||||
|
github.com/ncruces/go-sqlite3 v0.29.0/go.mod h1:r1hSvYKPNJ+OlUA1O3r8o9LAawzPAlqeZiIdxTBBBJ0=
|
||||||
|
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
|
||||||
|
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA=
|
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA=
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import (
|
|||||||
"go.senan.xyz/gonic/lastfm"
|
"go.senan.xyz/gonic/lastfm"
|
||||||
"go.senan.xyz/gonic/lastfm/mockclient"
|
"go.senan.xyz/gonic/lastfm/mockclient"
|
||||||
"go.senan.xyz/gonic/mockfs"
|
"go.senan.xyz/gonic/mockfs"
|
||||||
|
|
||||||
|
_ "github.com/ncruces/go-sqlite3/driver"
|
||||||
|
_ "github.com/ncruces/go-sqlite3/embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInfoCache(t *testing.T) {
|
func TestInfoCache(t *testing.T) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
package mockfs
|
package mockfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -299,23 +298,6 @@ func (m *MockFS) SetTags(path string, cb func(*TagInfo)) {
|
|||||||
cb(m.tagReader.paths[absPath])
|
cb(m.tagReader.paths[absPath])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockFS) DumpDB(suffix ...string) {
|
|
||||||
var p []string
|
|
||||||
p = append(p,
|
|
||||||
"gonic", "dump",
|
|
||||||
strings.ReplaceAll(m.t.Name(), string(filepath.Separator), "-"),
|
|
||||||
fmt.Sprint(time.Now().UnixNano()),
|
|
||||||
)
|
|
||||||
p = append(p, suffix...)
|
|
||||||
|
|
||||||
destPath := filepath.Join(os.TempDir(), strings.Join(p, "-"))
|
|
||||||
if err := db.Dump(context.Background(), m.db.DB, destPath); err != nil {
|
|
||||||
m.t.Fatalf("dumping db: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m.t.Error(destPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
type tagReader struct {
|
type tagReader struct {
|
||||||
paths map[string]*TagInfo
|
paths map[string]*TagInfo
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user