db migration

This commit is contained in:
Hayden 2023-03-04 22:20:17 -09:00
parent 37857682e6
commit 9f59a5d393
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 22 additions and 1 deletions

View file

@ -0,0 +1,20 @@
-- disable the enforcement of foreign-keys constraints
PRAGMA foreign_keys = off;
-- create "new_notifiers" table
CREATE TABLE `new_notifiers` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `url` text NOT NULL, `is_active` bool NOT NULL DEFAULT true, `group_id` uuid NOT NULL, `user_id` uuid NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `notifiers_groups_notifiers` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `notifiers_users_notifiers` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE);
-- copy rows from old table "notifiers" to new temporary table "new_notifiers"
INSERT INTO `new_notifiers` (`id`, `created_at`, `updated_at`, `name`, `url`, `is_active`, `user_id`) SELECT `id`, `created_at`, `updated_at`, `name`, `url`, `is_active`, `user_id` FROM `notifiers`;
-- drop "notifiers" table after copying rows
DROP TABLE `notifiers`;
-- rename temporary table "new_notifiers" to "notifiers"
ALTER TABLE `new_notifiers` RENAME TO `notifiers`;
-- create index "notifier_user_id" to table: "notifiers"
CREATE INDEX `notifier_user_id` ON `notifiers` (`user_id`);
-- create index "notifier_user_id_is_active" to table: "notifiers"
CREATE INDEX `notifier_user_id_is_active` ON `notifiers` (`user_id`, `is_active`);
-- create index "notifier_group_id" to table: "notifiers"
CREATE INDEX `notifier_group_id` ON `notifiers` (`group_id`);
-- create index "notifier_group_id_is_active" to table: "notifiers"
CREATE INDEX `notifier_group_id_is_active` ON `notifiers` (`group_id`, `is_active`);
-- enable back the enforcement of foreign-keys constraints
PRAGMA foreign_keys = on;

View file

@ -1,4 +1,4 @@
h1:ZyM3lKzq56l2l2mr1wjKS6sl7vS1i1gCMEw3aWz6Bjk=
h1:VjVLPBHzJ8N1Hiw+Aeitb0alnVn9UFilnajCzc+pie8=
20220929052825_init.sql h1:ZlCqm1wzjDmofeAcSX3jE4h4VcdTNGpRg2eabztDy9Q=
20221001210956_group_invitations.sql h1:YQKJFtE39wFOcRNbZQ/d+ZlHwrcfcsZlcv/pLEYdpjw=
20221009173029_add_user_roles.sql h1:vWmzAfgEWQeGk0Vn70zfVPCcfEZth3E0JcvyKTjpYyU=
@ -11,3 +11,4 @@ h1:ZyM3lKzq56l2l2mr1wjKS6sl7vS1i1gCMEw3aWz6Bjk=
20221205234812_cascade_delete_roles.sql h1:VIiaImR48nCHF3uFbOYOX1E79Ta5HsUBetGaSAbh9Gk=
20230227024134_add_scheduled_date.sql h1:8qO5OBZ0AzsfYEQOAQQrYIjyhSwM+v1A+/ylLSoiyoc=
20230305065819_add_notifier_types.sql h1:r5xrgCKYQ2o9byBqYeAX1zdp94BLdaxf4vq9OmGHNl0=
20230305071524_add_group_id_to_notifiers.sql h1:xDShqbyClcFhvJbwclOHdczgXbdffkxXNWjV61hL/t4=