diff --git a/packages/api/src/resolvers/labels/index.ts b/packages/api/src/resolvers/labels/index.ts index 2d111b507..a2d369f03 100644 --- a/packages/api/src/resolvers/labels/index.ts +++ b/packages/api/src/resolvers/labels/index.ts @@ -20,7 +20,7 @@ import { analytics } from '../../utils/analytics' import { env } from '../../env' import { User } from '../../entity/user' import { Label } from '../../entity/label' -import { getManager, getRepository } from 'typeorm' +import { getManager, getRepository, ILike } from 'typeorm' import { setClaims } from '../../entity/utils' import { Link } from '../../entity/link' import { LinkLabel } from '../../entity/link_label' @@ -76,9 +76,10 @@ export const createLabelResolver = authorized< } } + // Check if label already exists ignoring case of name const existingLabel = await getRepository(Label).findOne({ where: { - name, + name: ILike(name), }, }) if (existingLabel) { diff --git a/packages/db/migrations/0070.do.update_labels_table.sql b/packages/db/migrations/0070.do.update_labels_table.sql index 47bd667eb..13262ca7c 100755 --- a/packages/db/migrations/0070.do.update_labels_table.sql +++ b/packages/db/migrations/0070.do.update_labels_table.sql @@ -6,7 +6,7 @@ BEGIN; ALTER TABLE omnivore.labels DROP COLUMN link_id, - ADD COLUMN color text NOT NULL, + ADD COLUMN color text NOT NULL DEFAULT '#000000', ADD COLUMN description text, ADD CONSTRAINT label_name_unique UNIQUE (user_id, name); @@ -18,4 +18,6 @@ CREATE TABLE omnivore.link_labels ( UNIQUE (link_id, label_id) ); +GRANT SELECT, INSERT, DELETE ON omnivore.link_labels TO omnivore_user; + COMMIT;