Skip to content

Commit

Permalink
Revert "change(database): use string id - composite keys does not wor…
Browse files Browse the repository at this point in the history
…k otherwise"

This reverts commit 97a9d4a.
  • Loading branch information
l3uddz committed Feb 2, 2020
1 parent 2354861 commit ac55893
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cmd/cutoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"github.com/l3uddz/wantarr/database"
pvrObj "github.com/l3uddz/wantarr/pvr"
stringutils "github.com/l3uddz/wantarr/utils/strings"
"github.com/spf13/cobra"
"github.com/tommysolsen/capitalise"
"time"
Expand Down Expand Up @@ -119,7 +118,7 @@ var cutoffCmd = &cobra.Command{

// add item to batch
searchItems = append(searchItems, pvrObj.MediaItem{
ItemId: stringutils.StringToInt(item.Id),
ItemId: item.Id,
AirDateUtc: item.AirDateUtc,
})

Expand Down
3 changes: 1 addition & 2 deletions cmd/missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"github.com/l3uddz/wantarr/database"
pvrObj "github.com/l3uddz/wantarr/pvr"
stringutils "github.com/l3uddz/wantarr/utils/strings"
"github.com/spf13/cobra"
"github.com/tommysolsen/capitalise"
"time"
Expand Down Expand Up @@ -119,7 +118,7 @@ var missingCmd = &cobra.Command{

// add item to batch
searchItems = append(searchItems, pvrObj.MediaItem{
ItemId: stringutils.StringToInt(item.Id),
ItemId: item.Id,
AirDateUtc: item.AirDateUtc,
})

Expand Down
5 changes: 2 additions & 3 deletions database/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package database
import (
"github.com/l3uddz/wantarr/pvr"
"github.com/pkg/errors"
"strconv"
)

func DeleteMissingItems(pvrName string, wantedType string, newMediaItems []pvr.MediaItem) (int, error) {
// build slice of new item ids
newItemIds := make(map[string]*string, 0)
newItemIds := make(map[int]*string, 0)

for _, item := range newMediaItems {
newItemIds[strconv.Itoa(item.ItemId)] = nil
newItemIds[item.ItemId] = nil
}

// begin transaction
Expand Down
2 changes: 1 addition & 1 deletion database/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package database
import "time"

type MediaItem struct {
Id string `gorm:"primary_key"`
Id int `gorm:"primary_key"`
PvrName string `gorm:"primary_key"`
WantedType string `gorm:"primary_key"`
AirDateUtc time.Time
Expand Down
3 changes: 1 addition & 2 deletions database/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package database
import (
"github.com/l3uddz/wantarr/pvr"
"github.com/pkg/errors"
"strconv"
)

func SetMediaItems(pvrName string, wantedType string, mediaItems []pvr.MediaItem) error {
Expand All @@ -21,7 +20,7 @@ func SetMediaItems(pvrName string, wantedType string, mediaItems []pvr.MediaItem

// create item if not exists
err := tx.Where(MediaItem{
Id: strconv.Itoa(item.ItemId),
Id: item.ItemId,
PvrName: pvrName,
WantedType: wantedType,
}).Assign(mediaItem).FirstOrCreate(&mediaItem).Error
Expand Down
13 changes: 0 additions & 13 deletions utils/strings/conv.go

This file was deleted.

0 comments on commit ac55893

Please sign in to comment.