Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename sqlite package to db #3897

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions internal/autotag/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"path/filepath"
"testing"

"github.com/stashapp/stash/pkg/db"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/txn"

_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"

// necessary to register custom migrations
_ "github.com/stashapp/stash/pkg/sqlite/migrations"
_ "github.com/stashapp/stash/pkg/db/migrations"
)

const testName = "Foo's Bar"
Expand All @@ -33,11 +33,11 @@ var existingStudioID int

const expectedMatchTitle = "expected match"

var db *sqlite.Database
var conn *db.Database
var r models.Repository

func testTeardown(databaseFile string) {
err := db.Close()
err := conn.Close()

if err != nil {
panic(err)
Expand All @@ -58,12 +58,12 @@ func runTests(m *testing.M) int {

f.Close()
databaseFile := f.Name()
db = sqlite.NewDatabase()
if err := db.Open(databaseFile); err != nil {
conn = db.NewDatabase()
if err := conn.Open(databaseFile); err != nil {
panic(fmt.Sprintf("Could not initialize database: %s", err.Error()))
}

r = db.TxnRepository()
r = conn.TxnRepository()

// defer close and delete the database
defer testTeardown(databaseFile)
Expand Down Expand Up @@ -479,11 +479,11 @@ func createGallery(ctx context.Context, w models.GalleryWriter, o *models.Galler
}

func withTxn(f func(ctx context.Context) error) error {
return txn.WithTxn(context.TODO(), db, f)
return txn.WithTxn(context.TODO(), conn, f)
}

func withDB(f func(ctx context.Context) error) error {
return txn.WithDatabase(context.TODO(), db, f)
return txn.WithDatabase(context.TODO(), conn, f)
}

func populateDB() error {
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestParsePerformerScenes(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, p := range performers {
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestParseStudioScenes(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range studios {
Expand Down Expand Up @@ -660,7 +660,7 @@ func TestParseTagScenes(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range tags {
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestParsePerformerImages(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, p := range performers {
Expand Down Expand Up @@ -771,7 +771,7 @@ func TestParseStudioImages(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range studios {
Expand Down Expand Up @@ -831,7 +831,7 @@ func TestParseTagImages(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range tags {
Expand Down Expand Up @@ -888,7 +888,7 @@ func TestParsePerformerGalleries(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, p := range performers {
Expand Down Expand Up @@ -943,7 +943,7 @@ func TestParseStudioGalleries(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range studios {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ func TestParseTagGalleries(t *testing.T) {
}

tagger := Tagger{
TxnManager: db,
TxnManager: conn,
}

for _, s := range tags {
Expand Down
44 changes: 22 additions & 22 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stashapp/stash/internal/dlna"
"github.com/stashapp/stash/internal/log"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/db"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/file"
file_image "github.com/stashapp/stash/pkg/file/image"
Expand All @@ -31,12 +32,11 @@ import (
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/scraper"
"github.com/stashapp/stash/pkg/session"
"github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/utils"
"github.com/stashapp/stash/ui"

// register custom migrations
_ "github.com/stashapp/stash/pkg/sqlite/migrations"
_ "github.com/stashapp/stash/pkg/db/migrations"
)

type SystemStatus struct {
Expand Down Expand Up @@ -127,7 +127,7 @@ type Manager struct {

DLNAService *dlna.Service

Database *sqlite.Database
Database *db.Database
Repository Repository

SceneService SceneService
Expand Down Expand Up @@ -170,7 +170,7 @@ func initialize() error {
l := initLog()
initProfiling(cfg.GetCPUProfilePath())

db := sqlite.NewDatabase()
conn := db.NewDatabase()

// start with empty paths
emptyPaths := paths.Paths{}
Expand All @@ -182,33 +182,33 @@ func initialize() error {
DownloadStore: NewDownloadStore(),
PluginCache: plugin.NewCache(cfg),

Database: db,
Repository: sqliteRepository(db),
Database: conn,
Repository: dbRepository(conn),
Paths: &emptyPaths,

scanSubs: &subscriptionManager{},
}

instance.SceneService = &scene.Service{
File: db.File,
Repository: db.Scene,
MarkerRepository: db.SceneMarker,
File: conn.File,
Repository: conn.Scene,
MarkerRepository: conn.SceneMarker,
PluginCache: instance.PluginCache,
Paths: instance.Paths,
Config: cfg,
}

instance.ImageService = &image.Service{
File: db.File,
Repository: db.Image,
File: conn.File,
Repository: conn.Image,
}

instance.GalleryService = &gallery.Service{
Repository: db.Gallery,
ImageFinder: db.Image,
Repository: conn.Gallery,
ImageFinder: conn.Image,
ImageService: instance.ImageService,
File: db.File,
Folder: db.Folder,
File: conn.File,
Folder: conn.Folder,
}

instance.JobManager = initJobManager()
Expand Down Expand Up @@ -239,7 +239,7 @@ func initialize() error {
}

if err := instance.PostInit(ctx); err != nil {
var migrationNeededErr *sqlite.MigrationNeededError
var migrationNeededErr *db.MigrationNeededError
if errors.As(err, &migrationNeededErr) {
logger.Warn(err.Error())
} else {
Expand All @@ -265,8 +265,8 @@ func initialize() error {
logger.Warnf("could not initialize FFMPEG subsystem: %v", err)
}

instance.Scanner = makeScanner(db, instance.PluginCache)
instance.Cleaner = makeCleaner(db, instance.PluginCache)
instance.Scanner = makeScanner(conn, instance.PluginCache)
instance.Cleaner = makeCleaner(conn, instance.PluginCache)

// if DLNA is enabled, start it now
if instance.Config.GetDLNADefaultEnabled() {
Expand All @@ -290,7 +290,7 @@ func galleryFileFilter(ctx context.Context, f file.File) bool {
return isZip(f.Base().Basename)
}

func makeScanner(db *sqlite.Database, pluginCache *plugin.Cache) *file.Scanner {
func makeScanner(db *db.Database, pluginCache *plugin.Cache) *file.Scanner {
return &file.Scanner{
Repository: file.Repository{
Manager: db,
Expand All @@ -317,7 +317,7 @@ func makeScanner(db *sqlite.Database, pluginCache *plugin.Cache) *file.Scanner {
}
}

func makeCleaner(db *sqlite.Database, pluginCache *plugin.Cache) *file.Cleaner {
func makeCleaner(db *db.Database, pluginCache *plugin.Cache) *file.Cleaner {
return &file.Cleaner{
FS: &file.OsFS{},
Repository: file.Repository{
Expand Down Expand Up @@ -503,7 +503,7 @@ func (s *Manager) SetBlobStoreOptions() {
storageType := s.Config.GetBlobsStorage()
blobsPath := s.Config.GetBlobsPath()

s.Database.SetBlobStoreOptions(sqlite.BlobStoreOptions{
s.Database.SetBlobStoreOptions(db.BlobStoreOptions{
UseFilesystem: storageType == config.BlobStorageTypeFilesystem,
UseDatabase: storageType == config.BlobStorageTypeDatabase,
Path: blobsPath,
Expand Down Expand Up @@ -676,7 +676,7 @@ func (s *Manager) Setup(ctx context.Context, input SetupInput) error {

// initialise the database
if err := s.PostInit(ctx); err != nil {
var migrationNeededErr *sqlite.MigrationNeededError
var migrationNeededErr *db.MigrationNeededError
if errors.As(err, &migrationNeededErr) {
logger.Warn(err.Error())
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/manager/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package manager
import (
"context"

"github.com/stashapp/stash/pkg/db"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/gallery"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/txn"
)

Expand Down Expand Up @@ -73,7 +73,7 @@ func (r *Repository) WithDB(ctx context.Context, fn txn.TxnFunc) error {
return txn.WithDatabase(ctx, r, fn)
}

func sqliteRepository(d *sqlite.Database) Repository {
func dbRepository(d *db.Database) Repository {
txnRepo := d.TxnRepository()

return Repository{
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/anonymise.go → pkg/db/anonymise.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions pkg/sqlite/anonymise_test.go → pkg/db/anonymise_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//go:build integration
// +build integration

package sqlite_test
package db_test

import (
"context"
"os"
"testing"

"github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/db"
)

func TestAnonymiser_Anonymise(t *testing.T) {
Expand All @@ -22,7 +22,7 @@ func TestAnonymiser_Anonymise(t *testing.T) {
defer os.Remove(f.Name())

// use existing database
anonymiser, err := sqlite.NewAnonymiser(db, f.Name())
anonymiser, err := db.NewAnonymiser(conn, f.Name())
if err != nil {
t.Errorf("Could not create anonymiser: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/batch.go → pkg/db/batch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

const defaultBatchSize = 1000

Expand Down
4 changes: 2 additions & 2 deletions pkg/sqlite/blob.go → pkg/db/blob.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand All @@ -11,10 +11,10 @@ import (
"github.com/doug-martin/goqu/v9/exp"
"github.com/jmoiron/sqlx"
"github.com/mattn/go-sqlite3"
"github.com/stashapp/stash/pkg/db/blob"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/sqlite/blob"
"github.com/stashapp/stash/pkg/utils"
"gopkg.in/guregu/null.v4"
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/sqlite/blob_migrate.go → pkg/db/blob_migrate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/blob_test.go → pkg/db/blob_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build integration
// +build integration

package sqlite_test
package db_test

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/common.go → pkg/db/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/database.go → pkg/db/database.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlite
package db

import (
"context"
Expand Down
Loading