aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/develop/create_schema_files.php26
-rw-r--r--phpBB/includes/db/migration/data/310/notifications.php64
-rw-r--r--phpBB/includes/db/migration/data/310/notifications2.php206
-rw-r--r--phpBB/install/schemas/firebird_schema.sql23
-rw-r--r--phpBB/install/schemas/mssql_schema.sql15
-rw-r--r--phpBB/install/schemas/mysql_40_schema.sql14
-rw-r--r--phpBB/install/schemas/mysql_41_schema.sql14
-rw-r--r--phpBB/install/schemas/oracle_schema.sql30
-rw-r--r--phpBB/install/schemas/postgres_schema.sql14
-rw-r--r--phpBB/install/schemas/sqlite_schema.sql13
10 files changed, 304 insertions, 115 deletions
diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php
index b454fb2c16..3121db391d 100644
--- a/phpBB/develop/create_schema_files.php
+++ b/phpBB/develop/create_schema_files.php
@@ -1317,16 +1317,20 @@ function get_schema_struct()
$schema_data['phpbb_notification_types'] = array(
'COLUMNS' => array(
- 'notification_type' => array('VCHAR:255', ''),
+ 'notification_type_id' => array('USINT', NULL, 'auto_increment'),
+ 'notification_type_name' => array('VCHAR:255', ''),
'notification_type_enabled' => array('BOOL', 1),
),
- 'PRIMARY_KEY' => array('notification_type', 'notification_type_enabled'),
+ 'PRIMARY_KEY' => array('notification_type_id'),
+ 'KEYS' => array(
+ 'type' => array('UNIQUE', array('notification_type_name')),
+ ),
);
$schema_data['phpbb_notifications'] = array(
'COLUMNS' => array(
- 'notification_id' => array('UINT', NULL, 'auto_increment'),
- 'item_type' => array('VCHAR:255', ''),
+ 'notification_id' => array('UINT:10', NULL, 'auto_increment'),
+ 'notification_type_id' => array('USINT', 0),
'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
@@ -1336,7 +1340,7 @@ function get_schema_struct()
),
'PRIMARY_KEY' => 'notification_id',
'KEYS' => array(
- 'item_ident' => array('INDEX', array('item_type', 'item_id')),
+ 'item_ident' => array('INDEX', array('notification_type_id', 'item_id')),
'user' => array('INDEX', array('user_id', 'notification_read')),
),
);
@@ -1814,12 +1818,12 @@ function get_schema_struct()
);
$schema_data['phpbb_user_notifications'] = array(
- 'COLUMNS' => array(
- 'item_type' => array('VCHAR:255', ''),
- 'item_id' => array('UINT', 0),
- 'user_id' => array('UINT', 0),
- 'method' => array('VCHAR:255', ''),
- 'notify' => array('BOOL', 1),
+ 'COLUMNS' => array(
+ 'notification_type_id' => array('USINT', 0),
+ 'item_id' => array('UINT', 0),
+ 'user_id' => array('UINT', 0),
+ 'method' => array('VCHAR:255', ''),
+ 'notify' => array('BOOL', 1),
),
);
diff --git a/phpBB/includes/db/migration/data/310/notifications.php b/phpBB/includes/db/migration/data/310/notifications.php
index 82bfd4cb2d..17c939d95a 100644
--- a/phpBB/includes/db/migration/data/310/notifications.php
+++ b/phpBB/includes/db/migration/data/310/notifications.php
@@ -91,70 +91,6 @@ class phpbb_db_migration_data_310_notifications extends phpbb_db_migration
),
)),
array('config.add', array('load_notifications', 1)),
- array('custom', array(array($this, 'convert_notifications'))),
);
}
-
- public function convert_notifications()
- {
- $convert_notifications = array(
- array(
- 'check' => ($this->config['allow_topic_notify']),
- 'item_type' => 'post',
- ),
- array(
- 'check' => ($this->config['allow_forum_notify']),
- 'item_type' => 'topic',
- ),
- array(
- 'check' => ($this->config['allow_bookmarks']),
- 'item_type' => 'bookmark',
- ),
- array(
- 'check' => ($this->config['allow_privmsg']),
- 'item_type' => 'pm',
- ),
- );
-
- foreach ($convert_notifications as $convert_data)
- {
- if ($convert_data['check'])
- {
- $sql = 'SELECT user_id, user_notify_type
- FROM ' . USERS_TABLE . '
- WHERE user_notify = 1';
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array(
- 'item_type' => $convert_data['item_type'],
- 'item_id' => 0,
- 'user_id' => $row['user_id'],
- 'method' => '',
- )));
-
- if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH)
- {
- $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array(
- 'item_type' => $convert_data['item_type'],
- 'item_id' => 0,
- 'user_id' => $row['user_id'],
- 'method' => 'email',
- )));
- }
-
- if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH)
- {
- $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array(
- 'item_type' => $convert_data['item_type'],
- 'item_id' => 0,
- 'user_id' => $row['user_id'],
- 'method' => 'jabber',
- )));
- }
- }
- $this->db->sql_freeresult($result);
- }
- }
- }
}
diff --git a/phpBB/includes/db/migration/data/310/notifications2.php b/phpBB/includes/db/migration/data/310/notifications2.php
new file mode 100644
index 0000000000..a3f29b073a
--- /dev/null
+++ b/phpBB/includes/db/migration/data/310/notifications2.php
@@ -0,0 +1,206 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
+*
+*/
+
+class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
+{
+ static public function depends_on()
+ {
+ return array('phpbb_db_migration_data_310_notifications');
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'drop_tables' => array(
+ $this->table_prefix . 'notification_types',
+ $this->table_prefix . 'notifications',
+ $this->table_prefix . 'user_notifications',
+ ),
+ 'add_tables' => array(
+ $this->table_prefix . 'notification_types' => array(
+ 'COLUMNS' => array(
+ 'notification_type_id' => array('USINT', NULL, 'auto_increment'),
+ 'notification_type_name' => array('VCHAR:255', ''),
+ 'notification_type_enabled' => array('BOOL', 1),
+ ),
+ 'PRIMARY_KEY' => array('notification_type_id'),
+ 'KEYS' => array(
+ 'type' => array('UNIQUE', array('notification_type_name')),
+ ),
+ ),
+ $this->table_prefix . 'notifications' => array(
+ 'COLUMNS' => array(
+ 'notification_id' => array('UINT:10', NULL, 'auto_increment'),
+ 'notification_type_id' => array('USINT', 0),
+ 'item_id' => array('UINT', 0),
+ 'item_parent_id' => array('UINT', 0),
+ 'user_id' => array('UINT', 0),
+ 'notification_read' => array('BOOL', 0),
+ 'notification_time' => array('TIMESTAMP', 1),
+ 'notification_data' => array('TEXT_UNI', ''),
+ ),
+ 'PRIMARY_KEY' => 'notification_id',
+ 'KEYS' => array(
+ 'item_ident' => array('INDEX', array('notification_type_id', 'item_id')),
+ 'user' => array('INDEX', array('user_id', 'notification_read')),
+ ),
+ ),
+ $this->table_prefix . 'user_notifications' => array(
+ 'COLUMNS' => array(
+ 'notification_type_id' => array('USINT', 0),
+ 'item_id' => array('UINT', 0),
+ 'user_id' => array('UINT', 0),
+ 'method' => array('VCHAR:255', ''),
+ 'notify' => array('BOOL', 1),
+ ),
+ 'PRIMARY_KEY' => array(
+ 'notification_type_id',
+ 'item_id',
+ 'user_id',
+ ),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_tables' => array(
+ $this->table_prefix . 'notification_types',
+ $this->table_prefix . 'notifications',
+ $this->table_prefix . 'user_notifications',
+ ),
+ 'add_tables' => array(
+ $this->table_prefix . 'notification_types' => array(
+ 'COLUMNS' => array(
+ 'notification_type' => array('VCHAR:255', ''),
+ 'notification_type_enabled' => array('BOOL', 1),
+ ),
+ 'PRIMARY_KEY' => array('notification_type', 'notification_type_enabled'),
+ ),
+ $this->table_prefix . 'notifications' => array(
+ 'COLUMNS' => array(
+ 'notification_id' => array('UINT', NULL, 'auto_increment'),
+ 'item_type' => array('VCHAR:255', ''),
+ 'item_id' => array('UINT', 0),
+ 'item_parent_id' => array('UINT', 0),
+ 'user_id' => array('UINT', 0),
+ 'notification_read' => array('BOOL', 0),
+ 'notification_time' => array('TIMESTAMP', 1),
+ 'notification_data' => array('TEXT_UNI', ''),
+ ),
+ 'PRIMARY_KEY' => 'notification_id',
+ 'KEYS' => array(
+ 'item_ident' => array('INDEX', array('item_type', 'item_id')),
+ 'user' => array('INDEX', array('user_id', 'notification_read')),
+ ),
+ ),
+ $this->table_prefix . 'user_notifications' => array(
+ 'COLUMNS' => array(
+ 'item_type' => array('VCHAR:255', ''),
+ 'item_id' => array('UINT', 0),
+ 'user_id' => array('UINT', 0),
+ 'method' => array('VCHAR:255', ''),
+ 'notify' => array('BOOL', 1),
+ ),
+ ),
+ ),
+ );
+ }
+
+ public function update_data()
+ {
+ return array(
+ array('custom', array(array($this, 'convert_notifications'))),
+ );
+ }
+
+ public function convert_notifications()
+ {
+ $insert_table = $this->table_prefix . 'user_notifications';
+
+ $sql = 'SELECT user_id, user_notify_type, user_notify_pm
+ FROM ' . USERS_TABLE;
+ $result = $this->db->sql_query($sql);
+
+ $sql_insert_data = array();
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $notification_methods = array();
+
+ // In-board notification
+ $notification_methods[] = '';
+
+ if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH)
+ {
+ $notification_methods[] = 'email';
+ }
+
+ if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH)
+ {
+ $notification_methods[] = 'jabber';
+ }
+
+ // Notifications for posts
+ foreach (array('post', 'topic') as $item_type)
+ {
+ $sql_insert_data = $this->add_method_rows(
+ $sql_insert_data,
+ $item_type,
+ 0,
+ $row['user_id'],
+ $notification_methods
+ );
+ }
+
+ if ($row['user_notify_pm'])
+ {
+ // Notifications for private messages
+ // User either gets all methods or no method
+ $sql_insert_data = $this->add_method_rows(
+ $sql_insert_data,
+ 'pm',
+ 0,
+ $row['user_id'],
+ $notification_methods
+ );
+ }
+
+ if (sizeof($sql_insert_data) > 500)
+ {
+ $this->db->sql_multi_insert($insert_table, $sql_insert_data);
+ $sql_insert_data = array();
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ if (!empty($sql_insert_data))
+ {
+ $this->db->sql_multi_insert($insert_table, $sql_insert_data);
+ }
+ }
+
+ protected function add_method_rows(array $sql_insert_data, $item_type, $item_id, $user_id, array $methods)
+ {
+ $row_base = array(
+ 'item_type' => $item_type,
+ 'item_id' => (int) $item_id,
+ 'user_id' => (int) $user_id,
+ );
+
+ foreach ($methods as $method)
+ {
+ $row_base['method'] = $method;
+ $sql_insert_data[] = $row_base;
+ }
+
+ return $sql_insert_data;
+ }
+}
diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql
index 18ca184c65..92227eb38c 100644
--- a/phpBB/install/schemas/firebird_schema.sql
+++ b/phpBB/install/schemas/firebird_schema.sql
@@ -642,17 +642,30 @@ END;;
# Table: 'phpbb_notification_types'
CREATE TABLE phpbb_notification_types (
- notification_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
+ notification_type_id INTEGER NOT NULL,
+ notification_type_name VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
notification_type_enabled INTEGER DEFAULT 1 NOT NULL
);;
-ALTER TABLE phpbb_notification_types ADD PRIMARY KEY (notification_type, notification_type_enabled);;
+ALTER TABLE phpbb_notification_types ADD PRIMARY KEY (notification_type_id);;
+
+CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types(notification_type_name);;
+
+CREATE GENERATOR phpbb_notification_types_gen;;
+SET GENERATOR phpbb_notification_types_gen TO 0;;
+
+CREATE TRIGGER t_phpbb_notification_types FOR phpbb_notification_types
+BEFORE INSERT
+AS
+BEGIN
+ NEW.notification_type_id = GEN_ID(phpbb_notification_types_gen, 1);
+END;;
# Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications (
notification_id INTEGER NOT NULL,
- item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
+ notification_type_id INTEGER DEFAULT 0 NOT NULL,
item_id INTEGER DEFAULT 0 NOT NULL,
item_parent_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL,
@@ -663,7 +676,7 @@ CREATE TABLE phpbb_notifications (
ALTER TABLE phpbb_notifications ADD PRIMARY KEY (notification_id);;
-CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications(item_type, item_id);;
+CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications(notification_type_id, item_id);;
CREATE INDEX phpbb_notifications_user ON phpbb_notifications(user_id, notification_read);;
CREATE GENERATOR phpbb_notifications_gen;;
@@ -1290,7 +1303,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch(notify_status)
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
- item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
+ notification_type_id INTEGER DEFAULT 0 NOT NULL,
item_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL,
method VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql
index 3530f9cd25..e869cbd1b5 100644
--- a/phpBB/install/schemas/mssql_schema.sql
+++ b/phpBB/install/schemas/mssql_schema.sql
@@ -793,7 +793,8 @@ GO
Table: 'phpbb_notification_types'
*/
CREATE TABLE [phpbb_notification_types] (
- [notification_type] [varchar] (255) DEFAULT ('') NOT NULL ,
+ [notification_type_id] [int] IDENTITY (1, 1) NOT NULL ,
+ [notification_type_name] [varchar] (255) DEFAULT ('') NOT NULL ,
[notification_type_enabled] [int] DEFAULT (1) NOT NULL
) ON [PRIMARY]
GO
@@ -801,18 +802,20 @@ GO
ALTER TABLE [phpbb_notification_types] WITH NOCHECK ADD
CONSTRAINT [PK_phpbb_notification_types] PRIMARY KEY CLUSTERED
(
- [notification_type],
- [notification_type_enabled]
+ [notification_type_id]
) ON [PRIMARY]
GO
+CREATE UNIQUE INDEX [type] ON [phpbb_notification_types]([notification_type_name]) ON [PRIMARY]
+GO
+
/*
Table: 'phpbb_notifications'
*/
CREATE TABLE [phpbb_notifications] (
[notification_id] [int] IDENTITY (1, 1) NOT NULL ,
- [item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
+ [notification_type_id] [int] DEFAULT (0) NOT NULL ,
[item_id] [int] DEFAULT (0) NOT NULL ,
[item_parent_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL ,
@@ -829,7 +832,7 @@ ALTER TABLE [phpbb_notifications] WITH NOCHECK ADD
) ON [PRIMARY]
GO
-CREATE INDEX [item_ident] ON [phpbb_notifications]([item_type], [item_id]) ON [PRIMARY]
+CREATE INDEX [item_ident] ON [phpbb_notifications]([notification_type_id], [item_id]) ON [PRIMARY]
GO
CREATE INDEX [user] ON [phpbb_notifications]([user_id], [notification_read]) ON [PRIMARY]
@@ -1588,7 +1591,7 @@ GO
Table: 'phpbb_user_notifications'
*/
CREATE TABLE [phpbb_user_notifications] (
- [item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
+ [notification_type_id] [int] DEFAULT (0) NOT NULL ,
[item_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL ,
[method] [varchar] (255) DEFAULT ('') NOT NULL ,
diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql
index 8c405677a8..70048ea6bd 100644
--- a/phpBB/install/schemas/mysql_40_schema.sql
+++ b/phpBB/install/schemas/mysql_40_schema.sql
@@ -452,16 +452,18 @@ CREATE TABLE phpbb_modules (
# Table: 'phpbb_notification_types'
CREATE TABLE phpbb_notification_types (
- notification_type varbinary(255) DEFAULT '' NOT NULL,
+ notification_type_id smallint(4) UNSIGNED NOT NULL auto_increment,
+ notification_type_name varbinary(255) DEFAULT '' NOT NULL,
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
- PRIMARY KEY (notification_type, notification_type_enabled)
+ PRIMARY KEY (notification_type_id),
+ UNIQUE type (notification_type_name)
);
# Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications (
- notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
- item_type varbinary(255) DEFAULT '' NOT NULL,
+ notification_id int(10) UNSIGNED NOT NULL auto_increment,
+ notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
@@ -469,7 +471,7 @@ CREATE TABLE phpbb_notifications (
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
notification_data blob NOT NULL,
PRIMARY KEY (notification_id),
- KEY item_ident (item_type, item_id),
+ KEY item_ident (notification_type_id, item_id),
KEY user (user_id, notification_read)
);
@@ -911,7 +913,7 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
- item_type varbinary(255) DEFAULT '' NOT NULL,
+ notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varbinary(255) DEFAULT '' NOT NULL,
diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql
index cb259aa57d..e5ab9ceafa 100644
--- a/phpBB/install/schemas/mysql_41_schema.sql
+++ b/phpBB/install/schemas/mysql_41_schema.sql
@@ -452,16 +452,18 @@ CREATE TABLE phpbb_modules (
# Table: 'phpbb_notification_types'
CREATE TABLE phpbb_notification_types (
- notification_type varchar(255) DEFAULT '' NOT NULL,
+ notification_type_id smallint(4) UNSIGNED NOT NULL auto_increment,
+ notification_type_name varchar(255) DEFAULT '' NOT NULL,
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
- PRIMARY KEY (notification_type, notification_type_enabled)
+ PRIMARY KEY (notification_type_id),
+ UNIQUE type (notification_type_name)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
# Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications (
- notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
- item_type varchar(255) DEFAULT '' NOT NULL,
+ notification_id int(10) UNSIGNED NOT NULL auto_increment,
+ notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
@@ -469,7 +471,7 @@ CREATE TABLE phpbb_notifications (
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
notification_data text NOT NULL,
PRIMARY KEY (notification_id),
- KEY item_ident (item_type, item_id),
+ KEY item_ident (notification_type_id, item_id),
KEY user (user_id, notification_read)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
@@ -911,7 +913,7 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
- item_type varchar(255) DEFAULT '' NOT NULL,
+ notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varchar(255) DEFAULT '' NOT NULL,
diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql
index 35f05e34cd..b2e7409c7a 100644
--- a/phpBB/install/schemas/oracle_schema.sql
+++ b/phpBB/install/schemas/oracle_schema.sql
@@ -870,19 +870,37 @@ END;
Table: 'phpbb_notification_types'
*/
CREATE TABLE phpbb_notification_types (
- notification_type varchar2(255) DEFAULT '' ,
+ notification_type_id number(4) NOT NULL,
+ notification_type_name varchar2(255) DEFAULT '' ,
notification_type_enabled number(1) DEFAULT '1' NOT NULL,
- CONSTRAINT pk_phpbb_notification_types PRIMARY KEY (notification_type, notification_type_enabled)
+ CONSTRAINT pk_phpbb_notification_types PRIMARY KEY (notification_type_id),
+ CONSTRAINT u_phpbb_type UNIQUE (notification_type_name)
)
/
+CREATE SEQUENCE phpbb_notification_types_seq
+/
+
+CREATE OR REPLACE TRIGGER t_phpbb_notification_types
+BEFORE INSERT ON phpbb_notification_types
+FOR EACH ROW WHEN (
+ new.notification_type_id IS NULL OR new.notification_type_id = 0
+)
+BEGIN
+ SELECT phpbb_notification_types_seq.nextval
+ INTO :new.notification_type_id
+ FROM dual;
+END;
+/
+
+
/*
Table: 'phpbb_notifications'
*/
CREATE TABLE phpbb_notifications (
- notification_id number(8) NOT NULL,
- item_type varchar2(255) DEFAULT '' ,
+ notification_id number(10) NOT NULL,
+ notification_type_id number(4) DEFAULT '0' NOT NULL,
item_id number(8) DEFAULT '0' NOT NULL,
item_parent_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL,
@@ -893,7 +911,7 @@ CREATE TABLE phpbb_notifications (
)
/
-CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id)
+CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id)
/
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read)
/
@@ -1702,7 +1720,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications'
*/
CREATE TABLE phpbb_user_notifications (
- item_type varchar2(255) DEFAULT '' ,
+ notification_type_id number(4) DEFAULT '0' NOT NULL,
item_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL,
method varchar2(255) DEFAULT '' ,
diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql
index 6dc507b46d..cd6de434b5 100644
--- a/phpBB/install/schemas/postgres_schema.sql
+++ b/phpBB/install/schemas/postgres_schema.sql
@@ -623,12 +623,16 @@ CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id
/*
Table: 'phpbb_notification_types'
*/
+CREATE SEQUENCE phpbb_notification_types_seq;
+
CREATE TABLE phpbb_notification_types (
- notification_type varchar(255) DEFAULT '' NOT NULL,
+ notification_type_id INT2 DEFAULT nextval('phpbb_notification_types_seq'),
+ notification_type_name varchar(255) DEFAULT '' NOT NULL,
notification_type_enabled INT2 DEFAULT '1' NOT NULL CHECK (notification_type_enabled >= 0),
- PRIMARY KEY (notification_type, notification_type_enabled)
+ PRIMARY KEY (notification_type_id)
);
+CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types (notification_type_name);
/*
Table: 'phpbb_notifications'
@@ -637,7 +641,7 @@ CREATE SEQUENCE phpbb_notifications_seq;
CREATE TABLE phpbb_notifications (
notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'),
- item_type varchar(255) DEFAULT '' NOT NULL,
+ notification_type_id INT2 DEFAULT '0' NOT NULL CHECK (notification_type_id >= 0),
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_id >= 0),
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
@@ -647,7 +651,7 @@ CREATE TABLE phpbb_notifications (
PRIMARY KEY (notification_id)
);
-CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
+CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
/*
@@ -1171,7 +1175,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications'
*/
CREATE TABLE phpbb_user_notifications (
- item_type varchar(255) DEFAULT '' NOT NULL,
+ notification_type_id INT2 DEFAULT '0' NOT NULL CHECK (notification_type_id >= 0),
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
method varchar(255) DEFAULT '' NOT NULL,
diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql
index ccb67ad46f..e12bb624b6 100644
--- a/phpBB/install/schemas/sqlite_schema.sql
+++ b/phpBB/install/schemas/sqlite_schema.sql
@@ -439,16 +439,17 @@ CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id
# Table: 'phpbb_notification_types'
CREATE TABLE phpbb_notification_types (
- notification_type varchar(255) NOT NULL DEFAULT '',
- notification_type_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1',
- PRIMARY KEY (notification_type, notification_type_enabled)
+ notification_type_id INTEGER PRIMARY KEY NOT NULL ,
+ notification_type_name varchar(255) NOT NULL DEFAULT '',
+ notification_type_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1'
);
+CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types (notification_type_name);
# Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications (
notification_id INTEGER PRIMARY KEY NOT NULL ,
- item_type varchar(255) NOT NULL DEFAULT '',
+ notification_type_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
@@ -457,7 +458,7 @@ CREATE TABLE phpbb_notifications (
notification_data text(65535) NOT NULL DEFAULT ''
);
-CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
+CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
# Table: 'phpbb_poll_options'
@@ -883,7 +884,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
- item_type varchar(255) NOT NULL DEFAULT '',
+ notification_type_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
method varchar(255) NOT NULL DEFAULT '',