Refactor encryption_channels_com table structure and add foreign key constraint
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
This commit is contained in:
parent
705460e8e8
commit
40f871dbea
1 changed files with 36 additions and 21 deletions
|
@ -1,26 +1,41 @@
|
||||||
create table encryption_channels_com
|
DROP TABLE IF EXISTS encryption_channels_com;
|
||||||
|
CREATE TABLE encryption_channels_com
|
||||||
(
|
(
|
||||||
uuid varchar(36) default uuid() not null comment 'The Unique Universal Identifier of the message for the encryption channel',
|
uuid varchar(36) DEFAULT uuid() NOT NULL COMMENT 'The Unique Universal Identifier of the message for the encryption channel',
|
||||||
channel_uuid varchar(36) not null comment 'The UUID of the channel that the message belongs to',
|
channel_uuid varchar(36) NOT NULL COMMENT 'The UUID of the channel that the message belongs to',
|
||||||
recipient enum ('CALLER', 'RECEIVER') not null comment 'The recipient of the message',
|
recipient ENUM ('CALLER', 'RECEIVER') NOT NULL COMMENT 'The recipient of the message',
|
||||||
status enum ('SENT', 'RECEIVED', 'REJECTED') default 'SENT' not null comment 'The status of the message, SENT being the default, RECEIVED is when the recipient receives the message successfully and REJECTED is when the message cannot be decrypted, or the checksum failed.',
|
status ENUM ('SENT', 'RECEIVED', 'REJECTED') DEFAULT 'SENT' NOT NULL COMMENT 'The status of the message, SENT being the default, RECEIVED is when the recipient receives the message successfully and REJECTED is when the message cannot be decrypted, or the checksum failed.',
|
||||||
checksum varchar(64) not null comment 'The SHA512 hash of the decrypted message contents',
|
checksum varchar(64) NOT NULL COMMENT 'The SHA512 hash of the decrypted message contents',
|
||||||
data text not null comment 'The data of the message',
|
data text NOT NULL COMMENT 'The data of the message',
|
||||||
timestamp timestamp default current_timestamp() not null comment 'The Timestamp of the message',
|
timestamp timestamp DEFAULT current_timestamp() NOT NULL COMMENT 'The Timestamp of the message',
|
||||||
primary key (uuid, channel_uuid) comment 'The Unique Primary Index Pair for the channel_uuid and uuid of the message',
|
PRIMARY KEY (uuid, channel_uuid) COMMENT 'The Unique Primary Index Pair for the channel_uuid and uuid of the message',
|
||||||
constraint encryption_channels_com_uuid_channel_uuid_uindex
|
CONSTRAINT encryption_channels_com_uuid_channel_uuid_uindex
|
||||||
unique (uuid, channel_uuid) comment 'The Unique Primary Index Pair for the channel_uuid and uuid of the message',
|
UNIQUE (uuid, channel_uuid) COMMENT 'The Unique Primary Index Pair for the channel_uuid and uuid of the message'
|
||||||
constraint encryption_channels_com_encryption_channels_uuid_fk
|
|
||||||
foreign key (channel_uuid) references encryption_channels (uuid)
|
|
||||||
on update cascade on delete cascade
|
|
||||||
)
|
)
|
||||||
comment 'The table for housing communication messages sent over encryption channels';
|
COMMENT 'The table for housing communication messages sent over encryption channels';
|
||||||
|
|
||||||
create index encryption_channels_com_recipient_index
|
CREATE INDEX encryption_channels_com_recipient_index
|
||||||
on encryption_channels_com (recipient)
|
ON encryption_channels_com (recipient)
|
||||||
comment 'The index of the recipient column used for indexing';
|
COMMENT 'The index of the recipient column used for indexing';
|
||||||
|
|
||||||
create index encryption_channels_com_timestamp_index
|
CREATE INDEX encryption_channels_com_timestamp_index
|
||||||
on encryption_channels_com (timestamp)
|
ON encryption_channels_com (timestamp)
|
||||||
comment 'The index of the Timestamp column';
|
COMMENT 'The index of the Timestamp column';
|
||||||
|
|
||||||
|
SET @constraint_exists = (
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM information_schema.table_constraints
|
||||||
|
WHERE constraint_name = 'encryption_channels_com_encryption_channels_uuid_fk'
|
||||||
|
AND table_name = 'encryption_channels_com'
|
||||||
|
);
|
||||||
|
|
||||||
|
SET @sql = IF(@constraint_exists = 0,
|
||||||
|
'ALTER TABLE encryption_channels_com
|
||||||
|
ADD CONSTRAINT encryption_channels_com_encryption_channels_uuid_fk
|
||||||
|
FOREIGN KEY (channel_uuid) REFERENCES encryption_channels (uuid)
|
||||||
|
ON UPDATE CASCADE ON DELETE CASCADE',
|
||||||
|
'SELECT 1');
|
||||||
|
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
Loading…
Add table
Reference in a new issue