From 70dbd87f49b2d76f486fa89891cdc932fa291d53 Mon Sep 17 00:00:00 2001 From: Xeronith Date: Mon, 7 Nov 2022 20:09:15 +0330 Subject: [PATCH] feat(components): :card_file_box: migration scripts --- .../scripts/activity_pub_follower.sql | 48 +++++++++++++++++++ .../activity_pub_follower_triggers.sql | 18 +++++++ 2 files changed, 66 insertions(+) create mode 100644 greataped/components/model/repository/scripts/activity_pub_follower.sql create mode 100644 greataped/components/model/repository/scripts/activity_pub_follower_triggers.sql diff --git a/greataped/components/model/repository/scripts/activity_pub_follower.sql b/greataped/components/model/repository/scripts/activity_pub_follower.sql new file mode 100644 index 0000000..2a0f3a6 --- /dev/null +++ b/greataped/components/model/repository/scripts/activity_pub_follower.sql @@ -0,0 +1,48 @@ +USE `###DATABASE###_history`; + +CREATE TABLE `activity_pub_followers` +( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `action` VARCHAR(16) NOT NULL, + `original_id` BIGINT NOT NULL, + `handle` VARCHAR(256) NOT NULL, + `inbox` VARCHAR(256) NOT NULL, + `subject` VARCHAR(256) NOT NULL, + `activity` VARCHAR(4096) NOT NULL, + `accepted` BIT(1) NOT NULL, + `editor` BIGINT NOT NULL, + `status` BIGINT NOT NULL, + `sort_order` FLOAT NOT NULL, + `queued_at` BIGINT NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `triggered_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `changed_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `payload` JSON NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = `utf8mb4` + COLLATE = `utf8mb4_unicode_ci`; + +USE `###DATABASE###`; + +CREATE TABLE `activity_pub_followers` +( + `id` BIGINT NOT NULL, + `handle` VARCHAR(256) NOT NULL, + `inbox` VARCHAR(256) NOT NULL, + `subject` VARCHAR(256) NOT NULL, + `activity` VARCHAR(4096) NOT NULL, + `accepted` BIT(1) NOT NULL, + `editor` BIGINT NOT NULL DEFAULT 0, + `status` BIGINT NOT NULL DEFAULT 0, + `sort_order` FLOAT NOT NULL DEFAULT 0, + `queued_at` BIGINT NOT NULL DEFAULT 0, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `payload` JSON NULL, + PRIMARY KEY (`id`), + INDEX (`status`) +) ENGINE = InnoDB + DEFAULT CHARSET = `utf8mb4` + COLLATE = `utf8mb4_unicode_ci`; diff --git a/greataped/components/model/repository/scripts/activity_pub_follower_triggers.sql b/greataped/components/model/repository/scripts/activity_pub_follower_triggers.sql new file mode 100644 index 0000000..d2aa39d --- /dev/null +++ b/greataped/components/model/repository/scripts/activity_pub_follower_triggers.sql @@ -0,0 +1,18 @@ + +USE `###DATABASE###`; + +CREATE TRIGGER `activity_pub_followers_after_update` +AFTER UPDATE +ON `activity_pub_followers` FOR EACH ROW +BEGIN + INSERT INTO `###DATABASE###_history`.`activity_pub_followers`(`action`, `original_id`, `handle`, `inbox`, `subject`, `activity`, `accepted`, `editor`, `status`, `sort_order`, `queued_at`, `created_at`, `updated_at`, `payload`) + VALUES('update', `old`.`id`, `old`.`handle`, `old`.`inbox`, `old`.`subject`, `old`.`activity`, `old`.`accepted`, `old`.`editor`, `old`.`status`, `old`.`sort_order`, `old`.`queued_at`, `old`.`created_at`, `old`.`updated_at`, `old`.`payload`); +END; + +CREATE TRIGGER `activity_pub_followers_after_delete` +AFTER DELETE +ON `activity_pub_followers` FOR EACH ROW +BEGIN + INSERT INTO `###DATABASE###_history`.`activity_pub_followers`(`action`, `original_id`, `handle`, `inbox`, `subject`, `activity`, `accepted`, `editor`, `status`, `sort_order`, `queued_at`, `created_at`, `updated_at`, `payload`) + VALUES('delete', `old`.`id`, `old`.`handle`, `old`.`inbox`, `old`.`subject`, `old`.`activity`, `old`.`accepted`, `old`.`editor`, `old`.`status`, `old`.`sort_order`, `old`.`queued_at`, `old`.`created_at`, `old`.`updated_at`, `old`.`payload`); +END;