From 1c87146a50fd23cf945fa7096969702b22ef4dfa Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 27 Mar 2023 10:44:31 +0200 Subject: [PATCH] Add projects, environments, applications, databases --- app/Http/Controllers/HomeController.php | 12 +++++++ app/Models/Application.php | 11 +++++++ app/Models/Database.php | 11 +++++++ app/Models/Environment.php | 20 +++++++++++ app/Models/Project.php | 13 ++++++++ app/Models/ProjectSetting.php | 7 ++++ app/Models/Team.php | 3 ++ ...023_03_27_075351_create_projects_table.php | 33 +++++++++++++++++++ ...7_075443_create_project_settings_table.php | 32 ++++++++++++++++++ ...03_27_075444_create_environments_table.php | 33 +++++++++++++++++++ ..._075445_create_environmentsables_table.php | 30 +++++++++++++++++ ...03_27_081716_create_applications_table.php | 29 ++++++++++++++++ ...23_03_27_083620_create_databases_table.php | 29 ++++++++++++++++ database/seeders/ApplicationSeeder.php | 25 ++++++++++++++ database/seeders/DBSeeder.php | 21 ++++++++++++ database/seeders/DatabaseSeeder.php | 5 +++ database/seeders/EnvironmentSeeder.php | 24 ++++++++++++++ database/seeders/ProjectSeeder.php | 21 ++++++++++++ database/seeders/ProjectSettingSeeder.php | 20 +++++++++++ resources/views/components/navbar.blade.php | 2 +- resources/views/home.blade.php | 24 +++++++++++--- routes/web.php | 6 ++-- 22 files changed, 402 insertions(+), 9 deletions(-) create mode 100644 app/Http/Controllers/HomeController.php create mode 100644 app/Models/Application.php create mode 100644 app/Models/Database.php create mode 100644 app/Models/Environment.php create mode 100644 app/Models/Project.php create mode 100644 app/Models/ProjectSetting.php create mode 100644 database/migrations/2023_03_27_075351_create_projects_table.php create mode 100644 database/migrations/2023_03_27_075443_create_project_settings_table.php create mode 100644 database/migrations/2023_03_27_075444_create_environments_table.php create mode 100644 database/migrations/2023_03_27_075445_create_environmentsables_table.php create mode 100644 database/migrations/2023_03_27_081716_create_applications_table.php create mode 100644 database/migrations/2023_03_27_083620_create_databases_table.php create mode 100644 database/seeders/ApplicationSeeder.php create mode 100644 database/seeders/DBSeeder.php create mode 100644 database/seeders/EnvironmentSeeder.php create mode 100644 database/seeders/ProjectSeeder.php create mode 100644 database/seeders/ProjectSettingSeeder.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 000000000..f3e987682 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,12 @@ +projects; + return view('home', ['projects' => $projects]); + } +} diff --git a/app/Models/Application.php b/app/Models/Application.php new file mode 100644 index 000000000..0ac9475b8 --- /dev/null +++ b/app/Models/Application.php @@ -0,0 +1,11 @@ +morphToMany(Environment::class, 'environmentable'); + } +} diff --git a/app/Models/Database.php b/app/Models/Database.php new file mode 100644 index 000000000..5aa1f2747 --- /dev/null +++ b/app/Models/Database.php @@ -0,0 +1,11 @@ +morphToMany(Environment::class, 'environmentable'); + } +} diff --git a/app/Models/Environment.php b/app/Models/Environment.php new file mode 100644 index 000000000..a8a98cca6 --- /dev/null +++ b/app/Models/Environment.php @@ -0,0 +1,20 @@ +hasMany(EnvironmentAble::class); + } + public function applications() + { + return $this->morphedByMany(Application::class, 'environmentable'); + } + public function databases() + { + return $this->morphedByMany(Database::class, 'environmentable'); + } +} + diff --git a/app/Models/Project.php b/app/Models/Project.php new file mode 100644 index 000000000..1efe88548 --- /dev/null +++ b/app/Models/Project.php @@ -0,0 +1,13 @@ +hasMany(Environment::class); + } + public function settings() { + return $this->hasOne(ProjectSetting::class); + } +} diff --git a/app/Models/ProjectSetting.php b/app/Models/ProjectSetting.php new file mode 100644 index 000000000..78dcb32ba --- /dev/null +++ b/app/Models/ProjectSetting.php @@ -0,0 +1,7 @@ +hasMany(Project::class); + } } diff --git a/database/migrations/2023_03_27_075351_create_projects_table.php b/database/migrations/2023_03_27_075351_create_projects_table.php new file mode 100644 index 000000000..432496268 --- /dev/null +++ b/database/migrations/2023_03_27_075351_create_projects_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name'); + $table->string('description')->nullable(); + + $table->foreignId('team_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('projects'); + } +}; diff --git a/database/migrations/2023_03_27_075443_create_project_settings_table.php b/database/migrations/2023_03_27_075443_create_project_settings_table.php new file mode 100644 index 000000000..40e8bed1f --- /dev/null +++ b/database/migrations/2023_03_27_075443_create_project_settings_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('uuid')->unique(); + $table->string('wildcard_domain')->nullable(); + + $table->foreignId('project_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_settings'); + } +}; diff --git a/database/migrations/2023_03_27_075444_create_environments_table.php b/database/migrations/2023_03_27_075444_create_environments_table.php new file mode 100644 index 000000000..efb1bfcb4 --- /dev/null +++ b/database/migrations/2023_03_27_075444_create_environments_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name')->unique(); + + $table->nullableMorphs('environments_morph'); + + $table->foreignId('project_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('environments'); + } +}; diff --git a/database/migrations/2023_03_27_075445_create_environmentsables_table.php b/database/migrations/2023_03_27_075445_create_environmentsables_table.php new file mode 100644 index 000000000..36dd52ed1 --- /dev/null +++ b/database/migrations/2023_03_27_075445_create_environmentsables_table.php @@ -0,0 +1,30 @@ +id(); + $table->unsignedBigInteger('environment_id'); + $table->unsignedBigInteger('environmentable_id'); + $table->string('environmentable_type'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('environmentables'); + } +}; diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php new file mode 100644 index 000000000..bdfb38fef --- /dev/null +++ b/database/migrations/2023_03_27_081716_create_applications_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('applications'); + } +}; diff --git a/database/migrations/2023_03_27_083620_create_databases_table.php b/database/migrations/2023_03_27_083620_create_databases_table.php new file mode 100644 index 000000000..cf81de07f --- /dev/null +++ b/database/migrations/2023_03_27_083620_create_databases_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('databases'); + } +}; diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php new file mode 100644 index 000000000..f75b017b7 --- /dev/null +++ b/database/seeders/ApplicationSeeder.php @@ -0,0 +1,25 @@ + 1, + 'name' => 'My first application', + ]); + $environment_1->applications()->attach($application_1); + } +} diff --git a/database/seeders/DBSeeder.php b/database/seeders/DBSeeder.php new file mode 100644 index 000000000..adf09e048 --- /dev/null +++ b/database/seeders/DBSeeder.php @@ -0,0 +1,21 @@ + 1, + 'name'=> "My first database" + ]); + + $environment_1->databases()->attach($database_1); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 19606f85a..8f9ad67c7 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,6 +14,11 @@ public function run(): void TeamSeeder::class, ServerSeeder::class, PrivateKeySeeder::class, + ProjectSeeder::class, + ProjectSettingSeeder::class, + EnvironmentSeeder::class, + ApplicationSeeder::class, + DBSeeder::class, ]); } } diff --git a/database/seeders/EnvironmentSeeder.php b/database/seeders/EnvironmentSeeder.php new file mode 100644 index 000000000..b06a70c5f --- /dev/null +++ b/database/seeders/EnvironmentSeeder.php @@ -0,0 +1,24 @@ + 1, + 'name' => 'production', + 'project_id' => $project_1->id, + ]); + } +} diff --git a/database/seeders/ProjectSeeder.php b/database/seeders/ProjectSeeder.php new file mode 100644 index 000000000..c43a69e5c --- /dev/null +++ b/database/seeders/ProjectSeeder.php @@ -0,0 +1,21 @@ + 1, + 'name' => "My first project", + 'description' => "This is a test project in development", + 'team_id' => $root_team->id, + ]); + } +} diff --git a/database/seeders/ProjectSettingSeeder.php b/database/seeders/ProjectSettingSeeder.php new file mode 100644 index 000000000..050982bee --- /dev/null +++ b/database/seeders/ProjectSettingSeeder.php @@ -0,0 +1,20 @@ + 1, + 'wildcard_domain' => 'testing-host.localhost', + 'project_id' => $first_project->id, + ]); + } +} diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 008e4a57b..14507b8a6 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -1,10 +1,10 @@