diff --git a/database/migrations/2016_10_23_193810_add_foreign_keys_servers.php b/database/migrations/2016_10_23_193810_add_foreign_keys_servers.php new file mode 100644 index 000000000..59bc0ac39 --- /dev/null +++ b/database/migrations/2016_10_23_193810_add_foreign_keys_servers.php @@ -0,0 +1,65 @@ +foreign('node')->references('id')->on('nodes'); + $table->foreign('owner')->references('id')->on('users'); + $table->foreign('allocation')->references('id')->on('allocations'); + $table->foreign('service')->references('id')->on('services'); + $table->foreign('option')->references('id')->on('service_options'); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropForeign('servers_node_foreign'); + $table->dropForeign('servers_owner_foreign'); + $table->dropForeign('servers_allocation_foreign'); + $table->dropForeign('servers_service_foreign'); + $table->dropForeign('servers_option_foreign'); + + $table->dropIndex('servers_node_foreign'); + $table->dropIndex('servers_owner_foreign'); + $table->dropIndex('servers_allocation_foreign'); + $table->dropIndex('servers_service_foreign'); + $table->dropIndex('servers_option_foreign'); + + $table->dropColumn('deleted_at'); + }); + + DB::statement('ALTER TABLE servers + MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL, + MODIFY COLUMN owner MEDIUMINT(8) UNSIGNED NOT NULL, + MODIFY COLUMN allocation MEDIUMINT(8) UNSIGNED NOT NULL, + MODIFY COLUMN service MEDIUMINT(8) UNSIGNED NOT NULL, + MODIFY COLUMN servers.option MEDIUMINT(8) UNSIGNED NOT NULL + '); + } +} diff --git a/database/migrations/2016_10_23_201624_add_foreign_allocations.php b/database/migrations/2016_10_23_201624_add_foreign_allocations.php new file mode 100644 index 000000000..6b73df2d6 --- /dev/null +++ b/database/migrations/2016_10_23_201624_add_foreign_allocations.php @@ -0,0 +1,47 @@ +foreign('assigned_to')->references('id')->on('servers'); + $table->foreign('node')->references('id')->on('nodes'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('allocations', function (Blueprint $table) { + $table->dropForeign('allocations_assigned_to_foreign'); + $table->dropForeign('allocations_node_foreign'); + + $table->dropIndex('allocations_assigned_to_foreign'); + $table->dropIndex('allocations_node_foreign'); + }); + + DB::statement('ALTER TABLE allocations + MODIFY COLUMN assigned_to MEDIUMINT(8) UNSIGNED NULL, + MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL + '); + } +} diff --git a/database/migrations/2016_10_23_202222_add_foreign_api_keys.php b/database/migrations/2016_10_23_202222_add_foreign_api_keys.php new file mode 100644 index 000000000..67dcd3ce3 --- /dev/null +++ b/database/migrations/2016_10_23_202222_add_foreign_api_keys.php @@ -0,0 +1,33 @@ +foreign('user')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('api_keys', function (Blueprint $table) { + $table->dropForeign('api_keys_user_foreign'); + $table->dropIndex('api_keys_user_foreign'); + }); + } +} diff --git a/database/migrations/2016_10_23_202703_add_foreign_api_permissions.php b/database/migrations/2016_10_23_202703_add_foreign_api_permissions.php new file mode 100644 index 000000000..58bf1a5a5 --- /dev/null +++ b/database/migrations/2016_10_23_202703_add_foreign_api_permissions.php @@ -0,0 +1,37 @@ +foreign('key_id')->references('id')->on('api_keys'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('api_permissions', function (Blueprint $table) { + $table->dropForeign('api_permissions_key_id_foreign'); + $table->dropIndex('api_permissions_key_id_foreign'); + }); + + DB::statement('ALTER TABLE api_permissions MODIFY key_id MEDIUMINT(8) UNSIGNED NOT NULL'); + } +} diff --git a/database/migrations/2016_10_23_202953_add_foreign_database_servers.php b/database/migrations/2016_10_23_202953_add_foreign_database_servers.php new file mode 100644 index 000000000..b6f012dff --- /dev/null +++ b/database/migrations/2016_10_23_202953_add_foreign_database_servers.php @@ -0,0 +1,33 @@ +foreign('linked_node')->references('id')->on('nodes'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('database_servers', function (Blueprint $table) { + $table->dropForeign('database_servers_linked_node_foreign'); + $table->dropIndex('database_servers_linked_node_foreign'); + }); + } +} diff --git a/database/migrations/2016_10_23_203105_add_foreign_databases.php b/database/migrations/2016_10_23_203105_add_foreign_databases.php new file mode 100644 index 000000000..2d6b6e9a2 --- /dev/null +++ b/database/migrations/2016_10_23_203105_add_foreign_databases.php @@ -0,0 +1,37 @@ +foreign('server_id')->references('id')->on('servers'); + $table->foreign('db_server')->references('id')->on('database_servers'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('databases', function (Blueprint $table) { + $table->dropForeign('databases_server_id_foreign'); + $table->dropForeign('databases_db_server_foreign'); + + $table->dropIndex('databases_server_id_foreign'); + $table->dropIndex('databases_db_server_foreign'); + }); + } +} diff --git a/database/migrations/2016_10_23_203335_add_foreign_nodes.php b/database/migrations/2016_10_23_203335_add_foreign_nodes.php new file mode 100644 index 000000000..8fa516c00 --- /dev/null +++ b/database/migrations/2016_10_23_203335_add_foreign_nodes.php @@ -0,0 +1,37 @@ +foreign('location')->references('id')->on('locations'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nodes', function (Blueprint $table) { + $table->dropForeign('nodes_location_foreign'); + $table->dropIndex('nodes_location_foreign'); + }); + + DB::statement('ALTER TABLE nodes MODIFY location MEDIUMINT(10) UNSIGNED NOT NULL'); + } +} diff --git a/database/migrations/2016_10_23_203522_add_foreign_permissions.php b/database/migrations/2016_10_23_203522_add_foreign_permissions.php new file mode 100644 index 000000000..8de3f3b8f --- /dev/null +++ b/database/migrations/2016_10_23_203522_add_foreign_permissions.php @@ -0,0 +1,38 @@ +foreign('user_id')->references('id')->on('users'); + $table->foreign('server_id')->references('id')->on('servers'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('permissions', function (Blueprint $table) { + $table->dropForeign('permissions_user_id_foreign'); + $table->dropForeign('permissions_server_id_foreign'); + + $table->dropIndex('permissions_user_id_foreign'); + $table->dropIndex('permissions_server_id_foreign'); + }); + } + +} diff --git a/database/migrations/2016_10_23_203857_add_foreign_server_variables.php b/database/migrations/2016_10_23_203857_add_foreign_server_variables.php new file mode 100644 index 000000000..116434161 --- /dev/null +++ b/database/migrations/2016_10_23_203857_add_foreign_server_variables.php @@ -0,0 +1,48 @@ +foreign('server_id')->references('id')->on('servers'); + $table->foreign('variable_id')->references('id')->on('service_variables'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('server_variables', function (Blueprint $table) { + $table->dropForeign('server_variables_server_id_foreign'); + $table->dropForeign('server_variables_variable_id_foreign'); + + $table->dropIndex('server_variables_server_id_foreign'); + $table->dropIndex('server_variables_variable_id_foreign'); + }); + + DB::statement('ALTER TABLE allocations + MODIFY COLUMN server_id MEDIUMINT(8) UNSIGNED NULL, + MODIFY COLUMN variable_id MEDIUMINT(8) UNSIGNED NOT NULL + '); + } + +} diff --git a/database/migrations/2016_10_23_204157_add_foreign_service_options.php b/database/migrations/2016_10_23_204157_add_foreign_service_options.php new file mode 100644 index 000000000..0baad0c36 --- /dev/null +++ b/database/migrations/2016_10_23_204157_add_foreign_service_options.php @@ -0,0 +1,37 @@ +foreign('parent_service')->references('id')->on('services'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('service_options', function (Blueprint $table) { + $table->dropForeign('service_options_parent_service_foreign'); + $table->dropIndex('service_options_parent_service_foreign'); + }); + + DB::statement('ALTER TABLE service_options MODIFY parent_service MEDIUMINT(8) UNSIGNED NOT NULL'); + } +} diff --git a/database/migrations/2016_10_23_204321_add_foreign_service_variables.php b/database/migrations/2016_10_23_204321_add_foreign_service_variables.php new file mode 100644 index 000000000..4f7f43ae2 --- /dev/null +++ b/database/migrations/2016_10_23_204321_add_foreign_service_variables.php @@ -0,0 +1,37 @@ +foreign('option_id')->references('id')->on('service_options'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('service_variables', function (Blueprint $table) { + $table->dropForeign('service_variables_option_id_foreign'); + $table->dropIndex('service_variables_option_id_foreign'); + }); + + DB::statement('ALTER TABLE service_variables MODIFY option_id MEDIUMINT(8) UNSIGNED NOT NULL'); + } + } diff --git a/database/migrations/2016_10_23_204454_add_foreign_subusers.php b/database/migrations/2016_10_23_204454_add_foreign_subusers.php new file mode 100644 index 000000000..2f4045669 --- /dev/null +++ b/database/migrations/2016_10_23_204454_add_foreign_subusers.php @@ -0,0 +1,37 @@ +foreign('user_id')->references('id')->on('users'); + $table->foreign('server_id')->references('id')->on('servers'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('subusers', function (Blueprint $table) { + $table->dropForeign('subusers_user_id_foreign'); + $table->dropForeign('subusers_server_id_foreign'); + + $table->dropIndex('subusers_user_id_foreign'); + $table->dropIndex('subusers_server_id_foreign'); + }); + } +} diff --git a/database/migrations/2016_10_23_204610_add_foreign_tasks.php b/database/migrations/2016_10_23_204610_add_foreign_tasks.php new file mode 100644 index 000000000..77b736201 --- /dev/null +++ b/database/migrations/2016_10_23_204610_add_foreign_tasks.php @@ -0,0 +1,36 @@ +foreign('server')->references('id')->on('servers'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tasks', function (Blueprint $table) { + $table->dropForeign('tasks_server_foreign'); + $table->dropForeign('tasks_server_foreign'); + + $table->dropIndex('tasks_server_foreign'); + $table->dropIndex('tasks_server_foreign'); + }); + } +}