Skip to content

Commit

Permalink
EZP-30149: Unified eznotification table definition for MySQL and Post…
Browse files Browse the repository at this point in the history
…greSQL (#2550)

* [PostgreSQL] Changed eznotification.is_pending column data type to bool

eznotification.is_pending column data type needs to be compatible with
MySQL which is TINYINT(1) interpreted by Doctrine as boolean

* [MySQL] Changed eznotification.data column data type to TEXT

* [Tests][SQLite] Aligned SQLite integration tests schema with changes
  • Loading branch information
alongosz authored Mar 4, 2019
1 parent f6e6605 commit 5acabab
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ CREATE TABLE `eznotification` (
`is_pending` tinyint(1) NOT NULL DEFAULT '1',
`type` varchar(128) NOT NULL DEFAULT '',
`created` int(11) NOT NULL DEFAULT 0,
`data` blob,
`data` text,
PRIMARY KEY (`id`),
KEY `eznotification_owner` (`owner_id`),
KEY `eznotification_owner_is_pending` (`owner_id`, `is_pending`)
Expand Down
6 changes: 6 additions & 0 deletions data/update/mysql/dbupdate-7.4.0-to-7.5.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ ADD CONSTRAINT `ezcontentclass_attribute_ml_lang_fk`
REFERENCES `ezcontent_language` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;

--
-- EZP-30149: As a Developer I want uniform eznotification DB table definition across all DBMS-es
--

ALTER TABLE `eznotification` MODIFY COLUMN `data` TEXT;
9 changes: 8 additions & 1 deletion data/update/postgres/dbupdate-7.4.0-to-7.5.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
UPDATE ezsite_data SET value='7.5.0' WHERE name='ezpublish-version';

--
-- EZP-29990 - Add table for multilingual FieldDefinitions
-- EZP-29990: Add table for multilingual FieldDefinitions
--

DROP TABLE IF EXISTS ezcontentclass_attribute_ml;
Expand All @@ -24,3 +24,10 @@ ADD CONSTRAINT ezcontentclass_attribute_ml_lang_fk
REFERENCES ezcontent_language (id)
ON DELETE CASCADE
ON UPDATE CASCADE;

--
-- EZP-30149: As a Developer I want uniform eznotification DB table definition across all DBMS-es
--

ALTER TABLE eznotification ALTER COLUMN is_pending TYPE BOOLEAN;
ALTER TABLE eznotification ALTER COLUMN is_pending SET DEFAULT true;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function insert(CreateStruct $createStruct): int
self::COLUMN_TYPE => ':type',
self::COLUMN_DATA => ':data',
])
->setParameter(':is_pending', $createStruct->isPending, PDO::PARAM_INT)
->setParameter(':is_pending', $createStruct->isPending, PDO::PARAM_BOOL)
->setParameter(':user_id', $createStruct->ownerId, PDO::PARAM_INT)
->setParameter(':created', $createStruct->created, PDO::PARAM_INT)
->setParameter(':type', $createStruct->type, PDO::PARAM_STR)
Expand Down Expand Up @@ -93,7 +93,7 @@ public function updateNotification(Notification $notification): void
->update(self::TABLE_NOTIFICATION)
->set(self::COLUMN_IS_PENDING, ':is_pending')
->where($query->expr()->eq(self::COLUMN_ID, ':id'))
->setParameter(':is_pending', $notification->isPending, PDO::PARAM_INT)
->setParameter(':is_pending', $notification->isPending, PDO::PARAM_BOOL)
->setParameter(':id', $notification->id, PDO::PARAM_INT);

$query->execute();
Expand All @@ -120,11 +120,13 @@ public function countUserNotifications(int $userId): int
public function countUserPendingNotifications(int $userId): int
{
$query = $this->connection->createQueryBuilder();
$expr = $query->expr();
$query
->select('COUNT(' . self::COLUMN_ID . ')')
->from(self::TABLE_NOTIFICATION)
->where($query->expr()->eq(self::COLUMN_OWNER_ID, ':user_id'))
->andWhere($query->expr()->eq(self::COLUMN_IS_PENDING, true))
->where($expr->eq(self::COLUMN_OWNER_ID, ':user_id'))
->andWhere($expr->eq(self::COLUMN_IS_PENDING, ':is_pending'))
->setParameter(':is_pending', true, PDO::PARAM_BOOL)
->setParameter(':user_id', $userId, PDO::PARAM_INT);

return (int)$query->execute()->fetchColumn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ DROP TABLE IF EXISTS eznotification;
CREATE TABLE eznotification (
id SERIAL,
owner_id integer DEFAULT 0 NOT NULL ,
is_pending integer DEFAULT 1 NOT NULL,
is_pending boolean DEFAULT true NOT NULL,
type character varying(128) NOT NULL,
created integer DEFAULT 0 NOT NULL,
data text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ CREATE TABLE eznotification (
is_pending integer NOT NULL DEFAULT 1,
type text(255) NOT NULL DEFAULT '',
created integer NOT NULL DEFAULT 0,
data blob
data text
);

CREATE INDEX eznotification_owner ON eznotification(owner_id);
Expand Down

0 comments on commit 5acabab

Please sign in to comment.