added unique indexes to category

moved category methods down
This commit is contained in:
Philipp Häfelfinger 2019-04-06 23:07:11 +02:00
parent 2a4a8e2e01
commit 402ac902a5

View File

@ -70,22 +70,6 @@ func NewLocalDataStore() *LocalDataStore {
return &LocalDataStore{} return &LocalDataStore{}
} }
func (d *LocalDataStore) SaveCategory(category CategoryData) error {
panic("implement me")
}
func (d *LocalDataStore) GetCategoryByPiwigoId(id int) (CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) GetCategoryByKey(key string) (CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) GetCategoriesToCreate() ([]CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) Initialize(connectionString string) error { func (d *LocalDataStore) Initialize(connectionString string) error {
if connectionString == "" { if connectionString == "" {
return errors.New("connection string could not be empty.") return errors.New("connection string could not be empty.")
@ -286,10 +270,6 @@ func (d *LocalDataStore) SavePiwigoIdAndUpdateUploadFlag(md5Sum string, piwigoId
} }
_, err = stmt.Exec(piwigoId, uploadRequired, md5Sum) _, err = stmt.Exec(piwigoId, uploadRequired, md5Sum)
if err != nil {
return err
}
if err != nil { if err != nil {
logrus.Errorf("Rolling back transaction for piwigo id update of file %s", md5Sum) logrus.Errorf("Rolling back transaction for piwigo id update of file %s", md5Sum)
errTx := tx.Rollback() errTx := tx.Rollback()
@ -330,6 +310,22 @@ func (d *LocalDataStore) DeleteMarkedImages() error {
return tx.Commit() return tx.Commit()
} }
func (d *LocalDataStore) SaveCategory(category CategoryData) error {
panic("implement me")
}
func (d *LocalDataStore) GetCategoryByPiwigoId(id int) (CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) GetCategoryByKey(key string) (CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) GetCategoriesToCreate() ([]CategoryData, error) {
panic("implement me")
}
func (d *LocalDataStore) insertImageMetaData(tx *sql.Tx, data ImageMetaData) error { func (d *LocalDataStore) insertImageMetaData(tx *sql.Tx, data ImageMetaData) error {
stmt, err := tx.Prepare("INSERT INTO image (piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired) VALUES (?,?,?,?,?,?,?,?,?)") stmt, err := tx.Prepare("INSERT INTO image (piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired) VALUES (?,?,?,?,?,?,?,?,?)")
if err != nil { if err != nil {
@ -373,17 +369,28 @@ func (d *LocalDataStore) createTablesIfNeeded(db *sql.DB) error {
} }
_, err = db.Exec("CREATE TABLE IF NOT EXISTS category (" + _, err = db.Exec("CREATE TABLE IF NOT EXISTS category (" +
"CategoryId INTEGER PRIMARY KEY," + "categoryId INTEGER PRIMARY KEY," +
"PiwigoId INTEGER NULL," + "piwigoId INTEGER NULL," +
"PiwigoParentId INTEGER NULL," + "piwigoParentId INTEGER NULL," +
"Name NVARCHAR(255) NOT NULL," + "name NVARCHAR(255) NOT NULL," +
"Key NVARCHAR(1000) NOT NULL" + "key NVARCHAR(1000) NOT NULL" +
");") ");")
if err != nil { if err != nil {
return err return err
} }
return err _, err = db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UX_Category_Key ON category (key);")
if err != nil {
return err
}
_, err = db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UX_Category_PiwigoId ON category (piwigoId);")
if err != nil {
return err
}
logrus.Debug("Database successfully initialized")
return nil
} }
func (d *LocalDataStore) updateImageMetaData(tx *sql.Tx, data ImageMetaData) error { func (d *LocalDataStore) updateImageMetaData(tx *sql.Tx, data ImageMetaData) error {