Skip to content

Commit

Permalink
Added the database updates to federations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mleandrojr committed Jul 5, 2023
1 parent 25f57b9 commit 14fb5be
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions sql/update_2022-05-04_02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
CREATE TABLE `ada`.`federations` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`hash` varchar(32) NOT NULL,
`description` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_hash` (`hash`),
KEY `fk_federations_user_id_idx` (`user_id`),
CONSTRAINT `fk_federations_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4

ALTER TABLE `ada`.`chats`
ADD COLUMN `federation_id` INT UNSIGNED NULL AFTER `id`,
ADD INDEX `idx_federation_id` (`federation_id` ASC) VISIBLE;

ALTER TABLE `ada`.`chats`
ADD CONSTRAINT `fk_chats_federation_id`
FOREIGN KEY (`federation_id`)
REFERENCES `ada`.`federations` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE `ada`.`bans`
ADD COLUMN `federation_id` INT UNSIGNED NULL AFTER `chat_id`,
ADD INDEX `fk_bans_federation_id_idx` (`federation_id` ASC) VISIBLE;

ALTER TABLE `ada`.`bans`
ADD CONSTRAINT `fk_bans_federation_id`
FOREIGN KEY (`federation_id`)
REFERENCES `ada`.`federations` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

CREATE TABLE `ada`.`rel_users_federations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`federation_id` INT UNSIGNED NOT NULL,
`date` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `idx_uq_user_id_federation_id` (`user_id` ASC, `federation_id` ASC) VISIBLE,
INDEX `fk_rel_users_federations_federation_id_idx` (`federation_id` ASC) VISIBLE,
CONSTRAINT `fk_rel_users_federations_user_id`
FOREIGN KEY (`user_id`)
REFERENCES `ada`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_rel_users_federations_federation_id`
FOREIGN KEY (`federation_id`)
REFERENCES `ada`.`federations` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

0 comments on commit 14fb5be

Please sign in to comment.