Skip to content

Commit

Permalink
bugfix/create filter errors (#285)
Browse files Browse the repository at this point in the history
* Capture errors properly

* Fix field name constraints
  • Loading branch information
chadweimer authored Mar 2, 2021
1 parent 8dfd053 commit 6781534
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions db/migrations/postgres/0021_fix_search_field_enum.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TYPE recipe_field_name RENAME VALUE 'directions' TO 'description';

COMMIT;
5 changes: 5 additions & 0 deletions db/migrations/postgres/0021_fix_search_field_enum.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TYPE recipe_field_name RENAME VALUE 'description' TO 'directions';

COMMIT;
2 changes: 1 addition & 1 deletion db/migrations/sqlite3/0006_saved_searches.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE INDEX search_filter_user_id_idx ON search_filter(user_id);

CREATE TABLE search_filter_field (
search_filter_id INTEGER NOT NULL,
field_name TEXT CHECK(field_name IN ('name', 'ingredients', 'description')),
field_name TEXT CHECK(field_name IN ('name', 'ingredients', 'directions')),
UNIQUE(search_filter_id, field_name),
FOREIGN KEY(search_filter_id) REFERENCES search_filter(id) ON DELETE CASCADE
);
Expand Down
6 changes: 3 additions & 3 deletions db/user-postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ func (d *postgresUserDriver) createSearchFilterTx(filter *models.SavedSearchFilt
return err
}

d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
err = d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
if err != nil {
return err
}

d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
err = d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
if err != nil {
return err
}

d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
err = d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions db/user-sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ func (d *sqlUserDriver) createSearchFilterTx(filter *models.SavedSearchFilter, t
}
filter.ID, _ = res.LastInsertId()

d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
err = d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
if err != nil {
return err
}

d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
err = d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
if err != nil {
return err
}

d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
err = d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
if err != nil {
return err
}
Expand Down Expand Up @@ -337,17 +337,17 @@ func (d *sqlUserDriver) updateSearchFilterTx(filter *models.SavedSearchFilter, t
return err
}

d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
err = d.SetSearchFilterFieldsTx(filter.ID, filter.Fields, tx)
if err != nil {
return err
}

d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
err = d.SetSearchFilterStatesTx(filter.ID, filter.States, tx)
if err != nil {
return err
}

d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
err = d.SetSearchFilterTagsTx(filter.ID, filter.Tags, tx)
if err != nil {
return err
}
Expand Down

0 comments on commit 6781534

Please sign in to comment.