From 78ac6924e85da002c59ed0c752f6f70c0acf8845 Mon Sep 17 00:00:00 2001 From: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com> Date: Tue, 20 Dec 2022 03:07:51 +0530 Subject: [PATCH] Dnd remove default column value (#4337) * Revert "Revert dnd (#4294)" This reverts commit 9fac8f476ef43dd8d8977397c562f77fc92f64c0. * removed default value of new column for DND * Used a column function, and collases for default value * fix bad merge Co-authored-by: Scott Bishel --- server/services/store/sqlstore/category.go | 19 +++++++++++++++++-- .../000030_add_category_sort_order.up.sql | 2 +- ...0031_add_category_boards_sort_order.up.sql | 3 +-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/server/services/store/sqlstore/category.go b/server/services/store/sqlstore/category.go index 847c3d3d9..7b89461ce 100644 --- a/server/services/store/sqlstore/category.go +++ b/server/services/store/sqlstore/category.go @@ -13,9 +13,24 @@ import ( const categorySortOrderGap = 10 +func (s *SQLStore) categoryFields() []string { + return []string{ + "id", + "name", + "user_id", + "team_id", + "create_at", + "update_at", + "delete_at", + "collapsed", + "COALESCE(sort_order, 0)", + "type", + } +} + func (s *SQLStore) getCategory(db sq.BaseRunner, id string) (*model.Category, error) { query := s.getQueryBuilder(db). - Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at", "collapsed", "sort_order", "type"). + Select(s.categoryFields()...). From(s.tablePrefix + "categories"). Where(sq.Eq{"id": id}) @@ -149,7 +164,7 @@ func (s *SQLStore) deleteCategory(db sq.BaseRunner, categoryID, userID, teamID s func (s *SQLStore) getUserCategories(db sq.BaseRunner, userID, teamID string) ([]model.Category, error) { query := s.getQueryBuilder(db). - Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at", "collapsed", "sort_order", "type"). + Select(s.categoryFields()...). From(s.tablePrefix+"categories"). Where(sq.Eq{ "user_id": userID, diff --git a/server/services/store/sqlstore/migrations/000030_add_category_sort_order.up.sql b/server/services/store/sqlstore/migrations/000030_add_category_sort_order.up.sql index c5be380d7..d3e86526b 100644 --- a/server/services/store/sqlstore/migrations/000030_add_category_sort_order.up.sql +++ b/server/services/store/sqlstore/migrations/000030_add_category_sort_order.up.sql @@ -1,2 +1,2 @@ {{- /* addColumnIfNeeded tableName columnName datatype constraint */ -}} -{{ addColumnIfNeeded "categories" "sort_order" "BIGINT" "DEFAULT 0"}} +{{ addColumnIfNeeded "categories" "sort_order" "BIGINT" ""}} \ No newline at end of file diff --git a/server/services/store/sqlstore/migrations/000031_add_category_boards_sort_order.up.sql b/server/services/store/sqlstore/migrations/000031_add_category_boards_sort_order.up.sql index fb42d35e3..d655939ed 100644 --- a/server/services/store/sqlstore/migrations/000031_add_category_boards_sort_order.up.sql +++ b/server/services/store/sqlstore/migrations/000031_add_category_boards_sort_order.up.sql @@ -1,3 +1,2 @@ {{- /* addColumnIfNeeded tableName columnName datatype constraint */ -}} -{{ addColumnIfNeeded "category_boards" "sort_order" "BIGINT" "DEFAULT 0"}} - +{{ addColumnIfNeeded "category_boards" "sort_order" "BIGINT" ""}} \ No newline at end of file