simplify subscribing/unsubscribing podcasts
[mygpo.git] / install / update-12.sql
blobc1eab97a7bb88786425d109ef96ba826198e7de2
1 DELIMITER $$
2 DROP PROCEDURE IF EXISTS delete_inactive_users $$
3 CREATE PROCEDURE delete_inactive_users()
4 BEGIN
5     DECLARE deadlock INT DEFAULT 0;
6     DECLARE attempts INT DEFAULT 0;
7     DECLARE done INT DEFAULT 0;
8     DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
10     try_loop:WHILE (attempts<3) DO
11     BEGIN
12          DECLARE deadlock_detected CONDITION FOR 1213;
13          DECLARE EXIT HANDLER FOR deadlock_detected
14                 BEGIN
15                     ROLLBACK;
16                     SET deadlock=1;
17                 END;
18          SET deadlock=0;
19                
20          START TRANSACTION;
22             delete from auth_user where is_active=0 and datediff(date(now()), date(date_joined)) > 7;
24             COMMIT;  
25         END;
26         IF deadlock=0 THEN
27                 LEAVE try_loop;
28             ELSE
29                 SET attempts=attempts+1;
30             END IF;
31             END WHILE try_loop;
33         IF deadlock=1 THEN
34             call FAIL('Inactive users are not deleted!');
35         END IF;         
37 END $$
38 DELIMITER ;
40 DROP TABLE IF EXISTS `sanitizing_rules`;
41 CREATE TABLE `sanitizing_rules` (
42     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
43     `use_podcast` bool NOT NULL,
44     `use_episode` bool NOT NULL,
45     `search` varchar(100) NOT NULL,
46     `replace` varchar(100) NOT NULL,
47     `priority` integer UNSIGNED NOT NULL,
48     `description` longtext NOT NULL
51 alter table subscription add column id int unique auto_increment;
53 create unique index unique_subscription_meta on subscription (user_id, podcast_id);
55 create unique index unique_device_user_uid on device (user_id, uid);
57 alter table subscription_log change timestamp timestamp datetime not null;
58 alter table episode_log change timestamp timestamp datetime not null;