Created DemoSeederCommand to replace seeders. Closes #884
This commit is contained in:
276
app/Console/Commands/DemoSeederCommand.php
Normal file
276
app/Console/Commands/DemoSeederCommand.php
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Cachet\Console\Commands;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
|
use CachetHQ\Cachet\Models\Metric;
|
||||||
|
use CachetHQ\Cachet\Models\MetricPoint;
|
||||||
|
use CachetHQ\Cachet\Models\Setting;
|
||||||
|
use CachetHQ\Cachet\Models\User;
|
||||||
|
use DateInterval;
|
||||||
|
use DateTime;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the demo seeder command.
|
||||||
|
*
|
||||||
|
* @author James Brooks <james@alt-three.com>
|
||||||
|
*/
|
||||||
|
class DemoSeederCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name = 'cachet:seed';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Seeds Cachet with demo data.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function fire()
|
||||||
|
{
|
||||||
|
$this->seedComponents();
|
||||||
|
$this->seedIncidents();
|
||||||
|
$this->seedMetricPoints();
|
||||||
|
$this->seedMetrics();
|
||||||
|
$this->seedSettings();
|
||||||
|
$this->seedUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the components table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedComponents()
|
||||||
|
{
|
||||||
|
$defaultComponents = [
|
||||||
|
[
|
||||||
|
'name' => 'API',
|
||||||
|
'description' => 'Used by third-parties to connect to us',
|
||||||
|
'status' => 1,
|
||||||
|
'order' => 0,
|
||||||
|
'group_id' => 0,
|
||||||
|
'link' => '',
|
||||||
|
], [
|
||||||
|
'name' => 'Documentation',
|
||||||
|
'description' => 'Kindly powered by Readme.io',
|
||||||
|
'status' => 1,
|
||||||
|
'order' => 0,
|
||||||
|
'group_id' => 0,
|
||||||
|
'link' => 'https://docs.cachethq.io',
|
||||||
|
], [
|
||||||
|
'name' => 'Website',
|
||||||
|
'description' => '',
|
||||||
|
'status' => 1,
|
||||||
|
'order' => 0,
|
||||||
|
'group_id' => 0,
|
||||||
|
'link' => 'https://cachethq.io',
|
||||||
|
], [
|
||||||
|
'name' => 'Blog',
|
||||||
|
'description' => 'The Cachet Blog.',
|
||||||
|
'status' => 1,
|
||||||
|
'order' => 0,
|
||||||
|
'group_id' => 0,
|
||||||
|
'link' => 'https://blog.cachethq.io',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Component::truncate();
|
||||||
|
|
||||||
|
foreach ($defaultComponents as $component) {
|
||||||
|
Component::create($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the incidents table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedIncidents()
|
||||||
|
{
|
||||||
|
$defaultIncidents = [
|
||||||
|
[
|
||||||
|
'name' => 'Awesome',
|
||||||
|
'message' => 'We totally nailed the fix :smile:',
|
||||||
|
'status' => 4,
|
||||||
|
'component_id' => 0,
|
||||||
|
'scheduled_at' => null,
|
||||||
|
'visible' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Monitoring the fix',
|
||||||
|
'message' => "We're checking that our fix will first work.",
|
||||||
|
'status' => 3,
|
||||||
|
'component_id' => 0,
|
||||||
|
'scheduled_at' => null,
|
||||||
|
'visible' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Update',
|
||||||
|
'message' => "We've found the problem, so we're looking at it.",
|
||||||
|
'status' => 2,
|
||||||
|
'component_id' => 0,
|
||||||
|
'scheduled_at' => null,
|
||||||
|
'visible' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Test Incident',
|
||||||
|
'message' => 'Something went wrong, oh noes.',
|
||||||
|
'status' => 1,
|
||||||
|
'component_id' => 0,
|
||||||
|
'scheduled_at' => null,
|
||||||
|
'visible' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Incident::truncate();
|
||||||
|
|
||||||
|
foreach ($defaultIncidents as $incident) {
|
||||||
|
Incident::create($incident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the metric points table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedMetricPoints()
|
||||||
|
{
|
||||||
|
MetricPoint::truncate();
|
||||||
|
|
||||||
|
// Generate 11 hours of metric points
|
||||||
|
for ($i = 0; $i < 11; $i++) {
|
||||||
|
$metricTime = (new DateTime())->sub(new DateInterval('PT'.$i.'H'));
|
||||||
|
|
||||||
|
$point = MetricPoint::create([
|
||||||
|
'metric_id' => 1,
|
||||||
|
'value' => rand(1, 10),
|
||||||
|
'created_at' => $metricTime,
|
||||||
|
'updated_at' => $metricTime,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the metrics table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedMetrics()
|
||||||
|
{
|
||||||
|
$defaultMetrics = [
|
||||||
|
[
|
||||||
|
'name' => 'Cups of coffee',
|
||||||
|
'suffix' => 'Cups',
|
||||||
|
'description' => 'How many cups of coffee we\'ve drank.',
|
||||||
|
'default_value' => 0,
|
||||||
|
'calc_type' => 1,
|
||||||
|
'display_chart' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Metric::truncate();
|
||||||
|
|
||||||
|
foreach ($defaultMetrics as $metric) {
|
||||||
|
Metric::create($metric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the settings table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedSettings()
|
||||||
|
{
|
||||||
|
$defaultSettings = [
|
||||||
|
[
|
||||||
|
'name' => 'app_name',
|
||||||
|
'value' => 'Cachet Demo',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_domain',
|
||||||
|
'value' => 'https://demo.cachethq.io',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'show_support',
|
||||||
|
'value' => '1',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_locale',
|
||||||
|
'value' => 'en',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_timezone',
|
||||||
|
'value' => 'Europe/London',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_incident_days',
|
||||||
|
'value' => '7',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_analytics',
|
||||||
|
'value' => 'UA-58442674-3',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'app_analytics_gs',
|
||||||
|
'value' => 'GSN-712462-P',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'display_graphs',
|
||||||
|
'value' => '1',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Setting::truncate();
|
||||||
|
|
||||||
|
foreach ($defaultSettings as $setting) {
|
||||||
|
Setting::create($setting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the users table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function seedUsers()
|
||||||
|
{
|
||||||
|
$users = [
|
||||||
|
[
|
||||||
|
'username' => 'test',
|
||||||
|
'password' => 'test123',
|
||||||
|
'email' => 'test@test.com',
|
||||||
|
'level' => 1,
|
||||||
|
'api_key' => '9yMHsdioQosnyVK4iCVR',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
User::truncate();
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
User::create($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ class Kernel extends ConsoleKernel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
|
'CachetHQ\Cachet\Console\Commands\DemoSeederCommand',
|
||||||
'CachetHQ\Cachet\Console\Commands\FixPermissionsCommand',
|
'CachetHQ\Cachet\Console\Commands\FixPermissionsCommand',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
0
database/seeds/.gitkeep
Normal file
0
database/seeds/.gitkeep
Normal file
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\Component;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class ComponentTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$defaultComponents = [
|
|
||||||
[
|
|
||||||
'name' => 'API',
|
|
||||||
'description' => 'Used by third-parties to connect to us',
|
|
||||||
'status' => 1,
|
|
||||||
'order' => 0,
|
|
||||||
'group_id' => 0,
|
|
||||||
'link' => '',
|
|
||||||
], [
|
|
||||||
'name' => 'Documentation',
|
|
||||||
'description' => 'Kindly powered by Readme.io',
|
|
||||||
'status' => 1,
|
|
||||||
'order' => 0,
|
|
||||||
'group_id' => 0,
|
|
||||||
'link' => 'https://docs.cachethq.io',
|
|
||||||
], [
|
|
||||||
'name' => 'Website',
|
|
||||||
'description' => '',
|
|
||||||
'status' => 1,
|
|
||||||
'order' => 0,
|
|
||||||
'group_id' => 0,
|
|
||||||
'link' => 'https://cachethq.io',
|
|
||||||
], [
|
|
||||||
'name' => 'Blog',
|
|
||||||
'description' => 'The Cachet Blog.',
|
|
||||||
'status' => 1,
|
|
||||||
'order' => 0,
|
|
||||||
'group_id' => 0,
|
|
||||||
'link' => 'https://blog.cachethq.io',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
Component::truncate();
|
|
||||||
|
|
||||||
foreach ($defaultComponents as $component) {
|
|
||||||
Component::create($component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$this->call('UsersTableSeeder');
|
|
||||||
$this->call('SettingsTableSeeder');
|
|
||||||
$this->call('IncidentTableSeeder');
|
|
||||||
$this->call('ComponentTableSeeder');
|
|
||||||
$this->call('MetricTableSeeder');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class IncidentTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$defaultIncidents = [
|
|
||||||
[
|
|
||||||
'name' => 'Awesome',
|
|
||||||
'message' => 'We totally nailed the fix :smile:',
|
|
||||||
'status' => 4,
|
|
||||||
'component_id' => 0,
|
|
||||||
'scheduled_at' => null,
|
|
||||||
'visible' => 1,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Monitoring the fix',
|
|
||||||
'message' => "We're checking that our fix will first work.",
|
|
||||||
'status' => 3,
|
|
||||||
'component_id' => 0,
|
|
||||||
'scheduled_at' => null,
|
|
||||||
'visible' => 1,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Update',
|
|
||||||
'message' => "We've found the problem, so we're looking at it.",
|
|
||||||
'status' => 2,
|
|
||||||
'component_id' => 0,
|
|
||||||
'scheduled_at' => null,
|
|
||||||
'visible' => 1,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Test Incident',
|
|
||||||
'message' => 'Something went wrong, oh noes.',
|
|
||||||
'status' => 1,
|
|
||||||
'component_id' => 0,
|
|
||||||
'scheduled_at' => null,
|
|
||||||
'visible' => 1,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
Incident::truncate();
|
|
||||||
|
|
||||||
foreach ($defaultIncidents as $incident) {
|
|
||||||
Incident::create($incident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\MetricPoint;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class MetricPointSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
MetricPoint::truncate();
|
|
||||||
|
|
||||||
// Generate 11 hours of metric points
|
|
||||||
for ($i = 0; $i < 11; $i++) {
|
|
||||||
$metricTime = (new DateTime())->sub(new DateInterval('PT'.$i.'H'));
|
|
||||||
|
|
||||||
$point = MetricPoint::create([
|
|
||||||
'metric_id' => 1,
|
|
||||||
'value' => rand(1, 100),
|
|
||||||
'created_at' => $metricTime,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$point->update([
|
|
||||||
'created_at' => $metricTime,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\Metric;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class MetricTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$defaultMetrics = [
|
|
||||||
[
|
|
||||||
'name' => 'Cups of coffee',
|
|
||||||
'suffix' => 'Cups',
|
|
||||||
'description' => 'How many cups of coffee we\'ve drank.',
|
|
||||||
'default_value' => 0,
|
|
||||||
'calc_type' => 1,
|
|
||||||
'display_chart' => 1,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
Metric::truncate();
|
|
||||||
|
|
||||||
foreach ($defaultMetrics as $metric) {
|
|
||||||
Metric::create($metric);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\Setting;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class SettingsTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$defaultSettings = [
|
|
||||||
[
|
|
||||||
'name' => 'app_name',
|
|
||||||
'value' => 'Cachet Demo',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_domain',
|
|
||||||
'value' => 'https://demo.cachethq.io',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'show_support',
|
|
||||||
'value' => '1',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_locale',
|
|
||||||
'value' => 'en',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_timezone',
|
|
||||||
'value' => 'Europe/London',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_incident_days',
|
|
||||||
'value' => '7',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_analytics',
|
|
||||||
'value' => 'UA-58442674-3',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'app_analytics_gs',
|
|
||||||
'value' => 'GSN-712462-P',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'display_graphs',
|
|
||||||
'value' => '1',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
Setting::truncate();
|
|
||||||
|
|
||||||
foreach ($defaultSettings as $setting) {
|
|
||||||
Setting::create($setting);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Cachet.
|
|
||||||
*
|
|
||||||
* (c) Alt Three Services Limited
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use CachetHQ\Cachet\Models\User;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class UsersTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeding.
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$users = [
|
|
||||||
[
|
|
||||||
'username' => 'test',
|
|
||||||
'password' => 'test123',
|
|
||||||
'email' => 'test@test.com',
|
|
||||||
'level' => 1,
|
|
||||||
'api_key' => '9yMHsdioQosnyVK4iCVR',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
User::truncate();
|
|
||||||
|
|
||||||
foreach ($users as $user) {
|
|
||||||
User::create($user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user