SQLite model refactoring (#3791)

* Remove ID from PerformerPartial
* Separate studio model from sqlite model
* Separate movie model from sqlite model
* Separate tag model from sqlite model
* Separate saved filter model from sqlite model
* Separate scene marker model from sqlite model
* Separate gallery chapter model from sqlite model
* Move ErrNoRows checks into sqlite, improve empty result error messages
* Move SQLiteDate and SQLiteTimestamp to sqlite
* Use changesetTranslator everywhere, refactor for consistency
* Make PerformerStore.DestroyImage private
* Fix rating on movie create
This commit is contained in:
DingDongSoLong4
2023-06-15 04:46:09 +02:00
committed by GitHub
parent 9180a68c45
commit 1c13c9e1b1
150 changed files with 3279 additions and 3129 deletions

View File

@@ -63,7 +63,7 @@ func TestImporterPreImport(t *testing.T) {
assert.Nil(t, err)
expectedStudio := createFullStudio(0, 0)
expectedStudio.ParentID.Valid = false
expectedStudio.ParentID = nil
expectedStudio.Checksum = md5.FromString(studioName)
assert.Equal(t, expectedStudio, i.studio)
}
@@ -88,7 +88,7 @@ func TestImporterPreImportWithParent(t *testing.T) {
err := i.PreImport(ctx)
assert.Nil(t, err)
assert.Equal(t, int64(existingStudioID), i.studio.ParentID.Int64)
assert.Equal(t, existingStudioID, *i.studio.ParentID)
i.Input.ParentStudio = existingParentStudioErr
err = i.PreImport(ctx)
@@ -112,9 +112,10 @@ func TestImporterPreImportWithMissingParent(t *testing.T) {
}
readerWriter.On("FindByName", ctx, missingParentStudioName, false).Return(nil, nil).Times(3)
readerWriter.On("Create", ctx, mock.AnythingOfType("models.Studio")).Return(&models.Studio{
ID: existingStudioID,
}, nil)
readerWriter.On("Create", ctx, mock.AnythingOfType("*models.Studio")).Run(func(args mock.Arguments) {
s := args.Get(1).(*models.Studio)
s.ID = existingStudioID
}).Return(nil)
err := i.PreImport(ctx)
assert.NotNil(t, err)
@@ -126,7 +127,7 @@ func TestImporterPreImportWithMissingParent(t *testing.T) {
i.MissingRefBehaviour = models.ImportMissingRefEnumCreate
err = i.PreImport(ctx)
assert.Nil(t, err)
assert.Equal(t, int64(existingStudioID), i.studio.ParentID.Int64)
assert.Equal(t, existingStudioID, *i.studio.ParentID)
readerWriter.AssertExpectations(t)
}
@@ -146,7 +147,7 @@ func TestImporterPreImportWithMissingParentCreateErr(t *testing.T) {
}
readerWriter.On("FindByName", ctx, missingParentStudioName, false).Return(nil, nil).Once()
readerWriter.On("Create", ctx, mock.AnythingOfType("models.Studio")).Return(nil, errors.New("Create error"))
readerWriter.On("Create", ctx, mock.AnythingOfType("*models.Studio")).Return(errors.New("Create error"))
err := i.PreImport(ctx)
assert.NotNil(t, err)
@@ -227,11 +228,11 @@ func TestCreate(t *testing.T) {
ctx := context.Background()
studio := models.Studio{
Name: models.NullString(studioName),
Name: studioName,
}
studioErr := models.Studio{
Name: models.NullString(studioNameErr),
Name: studioNameErr,
}
i := Importer{
@@ -240,10 +241,11 @@ func TestCreate(t *testing.T) {
}
errCreate := errors.New("Create error")
readerWriter.On("Create", ctx, studio).Return(&models.Studio{
ID: studioID,
}, nil).Once()
readerWriter.On("Create", ctx, studioErr).Return(nil, errCreate).Once()
readerWriter.On("Create", ctx, &studio).Run(func(args mock.Arguments) {
s := args.Get(1).(*models.Studio)
s.ID = studioID
}).Return(nil).Once()
readerWriter.On("Create", ctx, &studioErr).Return(errCreate).Once()
id, err := i.Create(ctx)
assert.Equal(t, studioID, *id)
@@ -262,11 +264,11 @@ func TestUpdate(t *testing.T) {
ctx := context.Background()
studio := models.Studio{
Name: models.NullString(studioName),
Name: studioName,
}
studioErr := models.Studio{
Name: models.NullString(studioNameErr),
Name: studioNameErr,
}
i := Importer{
@@ -278,7 +280,7 @@ func TestUpdate(t *testing.T) {
// id needs to be set for the mock input
studio.ID = studioID
readerWriter.On("UpdateFull", ctx, studio).Return(nil, nil).Once()
readerWriter.On("Update", ctx, &studio).Return(nil).Once()
err := i.Update(ctx, studioID)
assert.Nil(t, err)
@@ -287,7 +289,7 @@ func TestUpdate(t *testing.T) {
// need to set id separately
studioErr.ID = errImageID
readerWriter.On("UpdateFull", ctx, studioErr).Return(nil, errUpdate).Once()
readerWriter.On("Update", ctx, &studioErr).Return(errUpdate).Once()
err = i.Update(ctx, errImageID)
assert.NotNil(t, err)