Skip to content

Commit

Permalink
Improved data insertion support for foreign keys (#460)
Browse files Browse the repository at this point in the history
* Improved data insertion support for foreign keys

* Added  table foreign key

* Upgrade telescope style
  • Loading branch information
guandeng authored and huangdijia committed Nov 24, 2023
1 parent 07d06a6 commit 7451c67
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/telescope/public/telescope/app.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/telescope/src/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function __construct(private ContainerInterface $container)
public function handle()
{
$connection = config('telescope.database.connection');
Db::connection($connection)->table('telescope_entries')->truncate();
Db::connection($connection)->table('telescope_entries_tags')->truncate();
Db::connection($connection)->table('telescope_monitoring')->truncate();
Db::connection($connection)->table('telescope_entries')->delete();
Db::connection($connection)->table('telescope_entries_tags')->delete();
Db::connection($connection)->table('telescope_monitoring')->delete();
}
}
3 changes: 0 additions & 3 deletions src/telescope/src/Command/PruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function handle()
Db::connection($connection)->table('telescope_entries')
->where('created_at', '<', $created_at)
->delete();
Db::connection($connection)
->table('telescope_entries_tags')
->delete();
Db::connection($connection)
->table('telescope_monitoring')
->delete();
Expand Down
16 changes: 13 additions & 3 deletions src/telescope/src/Controller/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public function index()
if (isset($item['content']['response'])) {
$item['content']['response'] = '';
}
$item['tag'] = '';
$item['tag'] = $item['tag_value'] = '';
foreach ($item['tags'] as $key => $val) {
if (Str::startsWith($val['tag'], 'app_name:')) {
$item['tag'] = $val['tag'];
$item['tag_value'] = $val['tag'];
$item['tag'] = Str::substr($val['tag'], strlen('app_name:'));
}
}
}
Expand All @@ -79,7 +80,16 @@ public function show($id)
$query->where('sub_batch_id', $entry->sub_batch_id);
}

$batch = $query->orderByDesc('sequence')->get();
$batch = $query->with('tags')->orderByDesc('sequence')->get();
foreach ($batch as &$item) {
$item['tag'] = $item['tag_value'] = '';
foreach ($item['tags'] as $key => $val) {
if (Str::startsWith($val['tag'], 'app_name:')) {
$item['tag_value'] = $val['tag'];
$item['tag'] = Str::substr($val['tag'], strlen('app_name:'));
}
}
}

return $this->response->json([
'entry' => $entry,
Expand Down
3 changes: 2 additions & 1 deletion src/telescope/src/IncomingEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ public function toArray(): array

public function create()
{
TelescopeEntryModel::create($this->toArray());

foreach ($this->tags as $tag) {
TelescopeEntryTagModel::create([
'entry_uuid' => $this->uuid,
'tag' => $tag,
]);
}
TelescopeEntryModel::create($this->toArray());
}
}

0 comments on commit 7451c67

Please sign in to comment.