Replace install.sql by database PIP
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 30 Sep 2021 14:17:36 +0000 (16:17 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 30 Sep 2021 14:17:36 +0000 (16:17 +0200)
The PHP definition already includes explicit INDEX names, because the two
indices in wcf1_conversation_to_user would conflict otherwise.

An update script will be added in a follow-up commit.

see WoltLab/WCF#4505

files/acp/database/install_com.woltlab.wcf.conversation.php [new file with mode: 0644]
install.sql [deleted file]
package.xml

diff --git a/files/acp/database/install_com.woltlab.wcf.conversation.php b/files/acp/database/install_com.woltlab.wcf.conversation.php
new file mode 100644 (file)
index 0000000..25e8e3d
--- /dev/null
@@ -0,0 +1,233 @@
+<?php
+
+/**
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license WoltLab License <http://www.woltlab.com/license-agreement.html>
+ */
+
+use wcf\system\database\table\column\DefaultFalseBooleanDatabaseTableColumn;
+use wcf\system\database\table\column\DefaultTrueBooleanDatabaseTableColumn;
+use wcf\system\database\table\column\IntDatabaseTableColumn;
+use wcf\system\database\table\column\MediumintDatabaseTableColumn;
+use wcf\system\database\table\column\MediumtextDatabaseTableColumn;
+use wcf\system\database\table\column\NotNullInt10DatabaseTableColumn;
+use wcf\system\database\table\column\NotNullVarchar255DatabaseTableColumn;
+use wcf\system\database\table\column\ObjectIdDatabaseTableColumn;
+use wcf\system\database\table\column\SmallintDatabaseTableColumn;
+use wcf\system\database\table\column\TextDatabaseTableColumn;
+use wcf\system\database\table\column\TinyintDatabaseTableColumn;
+use wcf\system\database\table\column\VarcharDatabaseTableColumn;
+use wcf\system\database\table\DatabaseTable;
+use wcf\system\database\table\index\DatabaseTableForeignKey;
+use wcf\system\database\table\index\DatabaseTableIndex;
+use wcf\system\database\table\index\DatabaseTablePrimaryIndex;
+use wcf\system\database\table\PartialDatabaseTable;
+
+return [
+    PartialDatabaseTable::create('wcf1_user_group')
+        ->columns([
+            DefaultFalseBooleanDatabaseTableColumn::create('canBeAddedAsConversationParticipant'),
+        ]),
+    DatabaseTable::create('wcf1_conversation')
+        ->columns([
+            ObjectIdDatabaseTableColumn::create('conversationID'),
+            NotNullVarchar255DatabaseTableColumn::create('subject')
+                ->defaultValue(''),
+            NotNullInt10DatabaseTableColumn::create('time')
+                ->defaultValue(0),
+            IntDatabaseTableColumn::create('firstMessageID')
+                ->length(10),
+            IntDatabaseTableColumn::create('userID')
+                ->length(10),
+            NotNullVarchar255DatabaseTableColumn::create('username')
+                ->defaultValue(''),
+            NotNullInt10DatabaseTableColumn::create('lastPostTime')
+                ->defaultValue(0),
+            IntDatabaseTableColumn::create('lastPosterID')
+                ->length(10),
+            NotNullVarchar255DatabaseTableColumn::create('lastPoster')
+                ->defaultValue(''),
+            MediumintDatabaseTableColumn::create('replies')
+                ->notNull()
+                ->defaultValue(0),
+            SmallintDatabaseTableColumn::create('attachments')
+                ->notNull()
+                ->defaultValue(0),
+            MediumintDatabaseTableColumn::create('participants')
+                ->notNull()
+                ->defaultValue(0),
+            TextDatabaseTableColumn::create('participantSummary'),
+            DefaultFalseBooleanDatabaseTableColumn::create('participantCanInvite'),
+            DefaultFalseBooleanDatabaseTableColumn::create('isClosed'),
+            DefaultFalseBooleanDatabaseTableColumn::create('isDraft'),
+            MediumtextDatabaseTableColumn::create('draftData'),
+        ])
+        ->indices([
+            DatabaseTablePrimaryIndex::create()
+                ->columns(['conversationID']),
+            DatabaseTableIndex::create('userID')
+                ->columns(['userID', 'isDraft']),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['userID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('SET NULL'),
+            DatabaseTableForeignKey::create()
+                ->columns(['lastPosterID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('SET NULL'),
+        ]),
+    DatabaseTable::create('wcf1_conversation_to_user')
+        ->columns([
+            NotNullInt10DatabaseTableColumn::create('conversationID'),
+            IntDatabaseTableColumn::create('participantID')
+                ->length(10),
+            NotNullVarchar255DatabaseTableColumn::create('username')
+                ->defaultValue(''),
+            TinyintDatabaseTableColumn::create('hideConversation')
+                ->length(1)
+                ->notNull()
+                ->defaultValue(0),
+            DefaultFalseBooleanDatabaseTableColumn::create('isInvisible'),
+            NotNullInt10DatabaseTableColumn::create('lastVisitTime')
+                ->defaultValue(0),
+            NotNullInt10DatabaseTableColumn::create('joinedAt')
+                ->defaultValue(0),
+            NotNullInt10DatabaseTableColumn::create('leftAt')
+                ->defaultValue(0),
+            IntDatabaseTableColumn::create('lastMessageID')
+                ->length(10),
+            DefaultTrueBooleanDatabaseTableColumn::create('leftByOwnChoice'),
+        ])
+        ->indices([
+            DatabaseTableIndex::create('participantID')
+                ->columns(['participantID', 'conversationID'])
+                ->type(DatabaseTableIndex::UNIQUE_TYPE),
+            DatabaseTableIndex::create('participantID_2')
+                ->columns(['participantID', 'hideConversation']),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['conversationID'])
+                ->referencedTable('wcf1_conversation')
+                ->referencedColumns(['conversationID'])
+                ->onDelete('CASCADE'),
+            DatabaseTableForeignKey::create()
+                ->columns(['participantID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('SET NULL'),
+        ]),
+    DatabaseTable::create('wcf1_conversation_message')
+        ->columns([
+            ObjectIdDatabaseTableColumn::create('messageID'),
+            NotNullInt10DatabaseTableColumn::create('conversationID'),
+            IntDatabaseTableColumn::create('userID')
+                ->length(10),
+            NotNullVarchar255DatabaseTableColumn::create('username')
+                ->defaultValue(''),
+            MediumtextDatabaseTableColumn::create('message')
+                ->notNull(),
+            NotNullInt10DatabaseTableColumn::create('time')
+                ->defaultValue(0),
+            SmallintDatabaseTableColumn::create('attachments')
+                ->notNull()
+                ->defaultValue(0),
+            DefaultFalseBooleanDatabaseTableColumn::create('enableHtml'),
+            VarcharDatabaseTableColumn::create('ipAddress')
+                ->length(39)
+                ->notNull()
+                ->defaultValue(''),
+            NotNullInt10DatabaseTableColumn::create('lastEditTime')
+                ->defaultValue(0),
+            MediumintDatabaseTableColumn::create('editCount')
+                ->length(7)
+                ->notNull()
+                ->defaultValue(0),
+            DefaultFalseBooleanDatabaseTableColumn::create('hasEmbeddedObjects'),
+        ])
+        ->indices([
+            DatabaseTablePrimaryIndex::create()
+                ->columns(['messageID']),
+            DatabaseTableIndex::create('conversationID')
+                ->columns(['conversationID', 'userID']),
+            DatabaseTableIndex::create('ipAddress')
+                ->columns(['ipAddress']),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['conversationID'])
+                ->referencedTable('wcf1_conversation')
+                ->referencedColumns(['conversationID'])
+                ->onDelete('CASCADE'),
+            DatabaseTableForeignKey::create()
+                ->columns(['userID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('SET NULL'),
+        ]),
+    PartialDatabaseTable::create('wcf1_conversation')
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['firstMessageID'])
+                ->referencedTable('wcf1_conversation_message')
+                ->referencedColumns(['messageID'])
+                ->onDelete('SET NULL'),
+        ]),
+    PartialDatabaseTable::create('wcf1_conversation_to_user')
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['lastMessageID'])
+                ->referencedTable('wcf1_conversation_message')
+                ->referencedColumns(['messageID'])
+                ->onDelete('SET NULL'),
+        ]),
+    DatabaseTable::create('wcf1_conversation_label')
+        ->columns([
+            ObjectIdDatabaseTableColumn::create('labelID'),
+            NotNullInt10DatabaseTableColumn::create('userID'),
+            VarcharDatabaseTableColumn::create('label')
+                ->length(80)
+                ->notNull()
+                ->defaultValue(''),
+            NotNullVarchar255DatabaseTableColumn::create('cssClassName')
+                ->defaultValue(''),
+        ])
+        ->indices([
+            DatabaseTablePrimaryIndex::create()
+                ->columns(['labelID']),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['userID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('CASCADE'),
+        ]),
+    DatabaseTable::create('wcf1_conversation_label_to_object')
+        ->columns([
+            NotNullInt10DatabaseTableColumn::create('labelID'),
+            NotNullInt10DatabaseTableColumn::create('conversationID'),
+        ])
+        ->indices([
+            DatabaseTableIndex::create('labelID')
+                ->columns(['labelID', 'conversationID'])
+                ->type(DatabaseTableIndex::UNIQUE_TYPE),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['labelID'])
+                ->referencedTable('wcf1_conversation_label')
+                ->referencedColumns(['labelID'])
+                ->onDelete('CASCADE'),
+            DatabaseTableForeignKey::create()
+                ->columns(['conversationID'])
+                ->referencedTable('wcf1_conversation')
+                ->referencedColumns(['conversationID'])
+                ->onDelete('CASCADE'),
+        ]),
+];
diff --git a/install.sql b/install.sql
deleted file mode 100644 (file)
index 2a8cd2f..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-DROP TABLE IF EXISTS wcf1_conversation;
-CREATE TABLE wcf1_conversation (
-       conversationID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-       subject VARCHAR(255) NOT NULL DEFAULT '',
-       time INT(10) NOT NULL DEFAULT 0,
-       firstMessageID INT(10),
-       userID INT(10),
-       username VARCHAR(255) NOT NULL DEFAULT '',
-       lastPostTime INT(10) NOT NULL DEFAULT 0,
-       lastPosterID INT(10),
-       lastPoster VARCHAR(255) NOT NULL DEFAULT '',
-       replies MEDIUMINT(7) NOT NULL DEFAULT 0,
-       attachments SMALLINT(5) NOT NULL DEFAULT 0,
-       participants MEDIUMINT(7) NOT NULL DEFAULT 0,
-       participantSummary TEXT,
-       participantCanInvite TINYINT(1) NOT NULL DEFAULT 0,
-       isClosed TINYINT(1) NOT NULL DEFAULT 0,
-       isDraft TINYINT(1) NOT NULL DEFAULT 0,
-       draftData MEDIUMTEXT,
-       
-       KEY (userID, isDraft)
-);
-
-DROP TABLE IF EXISTS wcf1_conversation_to_user;
-CREATE TABLE wcf1_conversation_to_user (
-       conversationID INT(10) NOT NULL,
-       participantID INT(10),
-       username VARCHAR(255) NOT NULL DEFAULT '',
-       hideConversation TINYINT(1) NOT NULL DEFAULT 0,
-       isInvisible TINYINT(1) NOT NULL DEFAULT 0,
-       lastVisitTime INT(10) NOT NULL DEFAULT 0,
-       joinedAt INT(10) NOT NULL DEFAULT 0,
-       leftAt INT(10) NOT NULL DEFAULT 0,
-       lastMessageID INT(10) NULL,
-       leftByOwnChoice TINYINT(1) NOT NULL DEFAULT 1,
-       
-       UNIQUE KEY (participantID, conversationID),
-       KEY (participantID, hideConversation)
-);
-
-DROP TABLE IF EXISTS wcf1_conversation_message;
-CREATE TABLE wcf1_conversation_message (
-       messageID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-       conversationID INT(10) NOT NULL,
-       userID INT(10),
-       username VARCHAR(255) NOT NULL DEFAULT '',
-       message MEDIUMTEXT NOT NULL,
-       time INT(10) NOT NULL DEFAULT 0,
-       attachments SMALLINT(5) NOT NULL DEFAULT 0,
-       enableHtml TINYINT(1) NOT NULL DEFAULT 0,
-       ipAddress VARCHAR(39) NOT NULL DEFAULT '',
-       lastEditTime INT(10) NOT NULL DEFAULT 0,
-       editCount MEDIUMINT(7) NOT NULL DEFAULT 0,
-       hasEmbeddedObjects TINYINT(1) NOT NULL DEFAULT 0,
-       
-       KEY (conversationID, userID),
-       KEY (ipAddress)
-);
-
--- labels
-DROP TABLE IF EXISTS wcf1_conversation_label;
-CREATE TABLE wcf1_conversation_label (
-       labelID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-       userID INT(10) NOT NULL,
-       label VARCHAR(80) NOT NULL DEFAULT '',
-       cssClassName VARCHAR(255) NOT NULL DEFAULT ''
-);
-
-DROP TABLE IF EXISTS wcf1_conversation_label_to_object;
-CREATE TABLE wcf1_conversation_label_to_object (
-       labelID INT(10) NOT NULL,
-       conversationID INT(10) NOT NULL,
-       
-       UNIQUE KEY (labelID, conversationID)
-);
-
-ALTER TABLE wcf1_user_group ADD canBeAddedAsConversationParticipant TINYINT(1) NOT NULL DEFAULT 0;
-
-ALTER TABLE wcf1_conversation ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
-ALTER TABLE wcf1_conversation ADD FOREIGN KEY (lastPosterID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
-ALTER TABLE wcf1_conversation ADD FOREIGN KEY (firstMessageID) REFERENCES wcf1_conversation_message (messageID) ON DELETE SET NULL;
-
-ALTER TABLE wcf1_conversation_to_user ADD FOREIGN KEY (conversationID) REFERENCES wcf1_conversation (conversationID) ON DELETE CASCADE;
-ALTER TABLE wcf1_conversation_to_user ADD FOREIGN KEY (participantID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
-ALTER TABLE wcf1_conversation_to_user ADD FOREIGN KEY (lastMessageID) REFERENCES wcf1_conversation_message (messageID) ON DELETE SET NULL;
-
-ALTER TABLE wcf1_conversation_message ADD FOREIGN KEY (conversationID) REFERENCES wcf1_conversation (conversationID) ON DELETE CASCADE;
-ALTER TABLE wcf1_conversation_message ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
-
-ALTER TABLE wcf1_conversation_label ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
-
-ALTER TABLE wcf1_conversation_label_to_object ADD FOREIGN KEY (labelID) REFERENCES wcf1_conversation_label (labelID) ON DELETE CASCADE;
-ALTER TABLE wcf1_conversation_label_to_object ADD FOREIGN KEY (conversationID) REFERENCES wcf1_conversation (conversationID) ON DELETE CASCADE;
index 66c053a15e7fdf26f5f69b65a8e4f26dbfca0278..c57adae80886922bb3eb2bc36310465e26b72f53 100644 (file)
@@ -24,8 +24,8 @@
        
        <instructions type="install">
                <instruction type="file" />
+               <instruction type="database">acp/database/install_com.woltlab.wcf.conversation.php</instruction>
                <instruction type="userGroupOption" />
-               <instruction type="sql" run="standalone" />
                <instruction type="template" />
                <instruction type="acpTemplate" />
                <instruction type="option" />