From 24ed50d9d2b1536d5599fd6f73cc3e77634950d7 Mon Sep 17 00:00:00 2001 From: Axel <1597611+axeloz@users.noreply.github.com> Date: Tue, 28 Dec 2021 13:34:50 +0100 Subject: [PATCH] Moving to migrations --- ...12_28_131705_create_contact_task_table.php | 32 +++++ ...021_12_28_131705_create_contacts_table.php | 36 +++++ .../2021_12_28_131705_create_groups_table.php | 31 +++++ ...2_28_131705_create_notifications_table.php | 34 +++++ ...12_28_131705_create_task_history_table.php | 36 +++++ ..._28_131705_create_tasks_archives_table.php | 33 +++++ .../2021_12_28_131705_create_tasks_table.php | 42 ++++++ ...add_foreign_keys_to_contact_task_table.php | 34 +++++ ...dd_foreign_keys_to_notifications_table.php | 34 +++++ ...add_foreign_keys_to_task_history_table.php | 32 +++++ ...131706_add_foreign_keys_to_tasks_table.php | 32 +++++ database/schema/mysql-schema.dump | 128 ------------------ 12 files changed, 376 insertions(+), 128 deletions(-) create mode 100644 database/migrations/2021_12_28_131705_create_contact_task_table.php create mode 100644 database/migrations/2021_12_28_131705_create_contacts_table.php create mode 100644 database/migrations/2021_12_28_131705_create_groups_table.php create mode 100644 database/migrations/2021_12_28_131705_create_notifications_table.php create mode 100644 database/migrations/2021_12_28_131705_create_task_history_table.php create mode 100644 database/migrations/2021_12_28_131705_create_tasks_archives_table.php create mode 100644 database/migrations/2021_12_28_131705_create_tasks_table.php create mode 100644 database/migrations/2021_12_28_131706_add_foreign_keys_to_contact_task_table.php create mode 100644 database/migrations/2021_12_28_131706_add_foreign_keys_to_notifications_table.php create mode 100644 database/migrations/2021_12_28_131706_add_foreign_keys_to_task_history_table.php create mode 100644 database/migrations/2021_12_28_131706_add_foreign_keys_to_tasks_table.php delete mode 100644 database/schema/mysql-schema.dump diff --git a/database/migrations/2021_12_28_131705_create_contact_task_table.php b/database/migrations/2021_12_28_131705_create_contact_task_table.php new file mode 100644 index 0000000..75434ae --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_contact_task_table.php @@ -0,0 +1,32 @@ +bigInteger('task_id')->unsigned(); + $table->bigInteger('contact_id')->unsigned(); + $table->primary(['task_id', 'contact_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('contact_task'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_contacts_table.php b/database/migrations/2021_12_28_131705_create_contacts_table.php new file mode 100644 index 0000000..44afb58 --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_contacts_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('surname', 200); + $table->string('firstname', 200); + $table->string('email', 250); + $table->string('phone', 20); + $table->timestamps(); + $table->tinyInteger('active')->default(1); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('contacts'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_groups_table.php b/database/migrations/2021_12_28_131705_create_groups_table.php new file mode 100644 index 0000000..dbe62c4 --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_groups_table.php @@ -0,0 +1,31 @@ +bigIncrements('id'); + $table->string('name', 128)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('groups'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_notifications_table.php b/database/migrations/2021_12_28_131705_create_notifications_table.php new file mode 100644 index 0000000..b02d408 --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_notifications_table.php @@ -0,0 +1,34 @@ +bigIncrements('id'); + $table->unsignedBigInteger('contact_id'); + $table->unsignedBigInteger('task_history_id'); + $table->enum('status', ['pending', 'sent', 'error'])->default('pending'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_task_history_table.php b/database/migrations/2021_12_28_131705_create_task_history_table.php new file mode 100644 index 0000000..cefb407 --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_task_history_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->unsignedTinyInteger('status'); + $table->text('output')->nullable(); + $table->float('duration', 5, 3)->unsigned()->nullable(); + $table->unsignedBigInteger('task_id'); + $table->timestamps(); + $table->index(['status', 'created_at']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('task_history'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_tasks_archives_table.php b/database/migrations/2021_12_28_131705_create_tasks_archives_table.php new file mode 100644 index 0000000..0af9497 --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_tasks_archives_table.php @@ -0,0 +1,33 @@ +bigIncrements('id'); + $table->date('day'); + $table->unsignedInteger('uptime')->default('0'); + $table->unsignedBigInteger('task_id')->default('0'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tasks_archives'); + } +} diff --git a/database/migrations/2021_12_28_131705_create_tasks_table.php b/database/migrations/2021_12_28_131705_create_tasks_table.php new file mode 100644 index 0000000..6f48eee --- /dev/null +++ b/database/migrations/2021_12_28_131705_create_tasks_table.php @@ -0,0 +1,42 @@ +bigIncrements('id'); + $table->string('host'); + $table->enum('type', ['ping', 'http', 'dns', 'ftp']); + $table->string('params')->nullable(); + $table->unsignedInteger('frequency'); + $table->unsignedTinyInteger('attempts')->default('0'); + $table->unsignedTinyInteger('active')->default(1); + $table->unsignedTinyInteger('status')->nullable(); + $table->unsignedBigInteger('group_id')->nullable(); + $table->timestamps(); + $table->timestamp('executed_at')->nullable(); + + $table->unique(['host', 'type']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tasks'); + } +} diff --git a/database/migrations/2021_12_28_131706_add_foreign_keys_to_contact_task_table.php b/database/migrations/2021_12_28_131706_add_foreign_keys_to_contact_task_table.php new file mode 100644 index 0000000..96f882e --- /dev/null +++ b/database/migrations/2021_12_28_131706_add_foreign_keys_to_contact_task_table.php @@ -0,0 +1,34 @@ +foreign(['task_id'], 'contact_task_ibfk_1')->references(['id'])->on('tasks')->onUpdate('NO ACTION')->onDelete('CASCADE'); + $table->foreign(['contact_id'], 'contact_task_ibfk_2')->references(['id'])->on('contacts')->onUpdate('NO ACTION')->onDelete('CASCADE'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('contact_task', function (Blueprint $table) { + $table->dropForeign('contact_task_ibfk_1'); + $table->dropForeign('contact_task_ibfk_2'); + }); + } +} diff --git a/database/migrations/2021_12_28_131706_add_foreign_keys_to_notifications_table.php b/database/migrations/2021_12_28_131706_add_foreign_keys_to_notifications_table.php new file mode 100644 index 0000000..e7ea638 --- /dev/null +++ b/database/migrations/2021_12_28_131706_add_foreign_keys_to_notifications_table.php @@ -0,0 +1,34 @@ +foreign(['contact_id'], 'contact_id_frgn')->references(['id'])->on('contacts')->onUpdate('NO ACTION')->onDelete('CASCADE'); + $table->foreign(['task_history_id'], 'task_history_id_frgn')->references(['id'])->on('task_history')->onUpdate('NO ACTION')->onDelete('CASCADE'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->dropForeign('contact_id_frgn'); + $table->dropForeign('task_history_id_frgn'); + }); + } +} diff --git a/database/migrations/2021_12_28_131706_add_foreign_keys_to_task_history_table.php b/database/migrations/2021_12_28_131706_add_foreign_keys_to_task_history_table.php new file mode 100644 index 0000000..1edf88f --- /dev/null +++ b/database/migrations/2021_12_28_131706_add_foreign_keys_to_task_history_table.php @@ -0,0 +1,32 @@ +foreign(['task_id'], 'task_history_ibfk_1')->references(['id'])->on('tasks')->onUpdate('NO ACTION')->onDelete('CASCADE'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('task_history', function (Blueprint $table) { + $table->dropForeign('task_history_ibfk_1'); + }); + } +} diff --git a/database/migrations/2021_12_28_131706_add_foreign_keys_to_tasks_table.php b/database/migrations/2021_12_28_131706_add_foreign_keys_to_tasks_table.php new file mode 100644 index 0000000..6e0d324 --- /dev/null +++ b/database/migrations/2021_12_28_131706_add_foreign_keys_to_tasks_table.php @@ -0,0 +1,32 @@ +foreign(['group_id'], 'group_id_frgn')->references(['id'])->on('groups')->onUpdate('NO ACTION')->onDelete('CASCADE'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tasks', function (Blueprint $table) { + $table->dropForeign('group_id_frgn'); + }); + } +} diff --git a/database/schema/mysql-schema.dump b/database/schema/mysql-schema.dump deleted file mode 100644 index d78bfb6..0000000 --- a/database/schema/mysql-schema.dump +++ /dev/null @@ -1,128 +0,0 @@ -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -DROP TABLE IF EXISTS `contact_task`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `contact_task` ( - `task_id` int unsigned NOT NULL, - `contact_id` int unsigned NOT NULL, - PRIMARY KEY (`task_id`,`contact_id`), - KEY `contact_id` (`contact_id`), - CONSTRAINT `contact_task_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE, - CONSTRAINT `contact_task_ibfk_2` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `contacts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `contacts` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `surname` varchar(200) NOT NULL, - `firstname` varchar(200) NOT NULL, - `email` varchar(250) NOT NULL, - `phone` varchar(20) NOT NULL, - `creation_date` datetime NOT NULL, - `active` int NOT NULL DEFAULT '1', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `groups`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `groups` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `migrations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `migrations` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, - `batch` int NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `notifications`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `notifications` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `contact_id` int unsigned NOT NULL DEFAULT '0', - `task_history_id` int unsigned NOT NULL DEFAULT '0', - `status` enum('pending','sent','error') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'pending', - `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:01', - `updated_at` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `contact_id_frgn` (`contact_id`), - KEY `task_history_id_frgn` (`task_history_id`), - CONSTRAINT `contact_id_frgn` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE, - CONSTRAINT `task_history_id_frgn` FOREIGN KEY (`task_history_id`) REFERENCES `task_history` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `task_history`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `task_history` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `status` int unsigned NOT NULL, - `output` text CHARACTER SET utf8 COLLATE utf8_general_ci, - `duration` float(5,3) unsigned DEFAULT NULL, - `task_id` int unsigned NOT NULL, - `created_at` datetime NOT NULL, - `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:01', - PRIMARY KEY (`id`), - KEY `task_id` (`task_id`), - KEY `status` (`status`,`created_at`) USING BTREE, - CONSTRAINT `task_history_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `tasks`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `tasks` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `host` varchar(255) NOT NULL, - `type` enum('ping','http') NOT NULL, - `params` varchar(255) NOT NULL, - `frequency` int unsigned NOT NULL, - `attempts` int unsigned NOT NULL DEFAULT '0', - `active` int NOT NULL DEFAULT '0', - `status` int unsigned DEFAULT NULL, - `group_id` int unsigned DEFAULT NULL, - `created_at` datetime NOT NULL, - `updated_at` datetime DEFAULT NULL, - `executed_at` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `host` (`host`,`type`), - KEY `group_id_frgn` (`group_id`), - KEY `attempts` (`attempts`) USING BTREE, - CONSTRAINT `group_id_frgn` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `tasks_archives`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `tasks_archives` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `day` date NOT NULL, - `uptime` int unsigned NOT NULL DEFAULT '0', - `task_id` int unsigned NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - -INSERT INTO `migrations` VALUES (1,'2021_12_21_101954_create_jobs_table',1); -INSERT INTO `migrations` VALUES (2,'2021_12_21_102355_create_failed_jobs_table',2);