Skip to content

Commit

Permalink
Merge pull request #84 from Justintime50/indexes
Browse files Browse the repository at this point in the history
indexes
  • Loading branch information
Justintime50 authored Sep 20, 2023
2 parents e6c0ce4 + 273571e commit dd59d29
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 33 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## Next Release

- Categories are now unique and required, enforced at the database level
- Various database indexes were added for common lookup patterns for quick retrieval
- Fixes a bug that didn't show the dropdown chevrons for form-select fields when creating a post
- Fixes a Bootstrap deprecation warning
- Updates MariaDB from 10.11 to 11.1

## v1.0.1 (2023-09-06)

- Fixes long-string line wrapping on the posts page when viewing on mobile
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
cpus: '0.25'
memory: '128M'
healthcheck:
test: ['CMD', 'mysql', '-u${MARIADB_USER}', '-p${MARIADB_PASSWORD}', '-e', 'show databases;']
test: ['CMD', 'mariadb', '-u${MARIADB_USER}', '-p${MARIADB_PASSWORD}', '-e', 'show databases;']
interval: 10s
timeout: 10s
retries: 3
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
depends_on:
- glass-db
glass-db:
image: 'mariadb:10.11.4'
image: 'mariadb:11.1.2'
restart: always
volumes:
- database-data:/var/lib/mysql
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function create(Request $request): RedirectResponse
->first() ?: new Category();

$request->validate([
'category' => 'required|string|unique:categories,category' . $category->id,
'category' => 'required|string',
]);

if ($category->trashed()) {
Expand Down
2 changes: 1 addition & 1 deletion src/database/factories/CategoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CategoryFactory extends Factory
public function definition()
{
return [
'category' => $this->faker->word(),
'category' => $this->faker->unique()->word(),
];
}
}
56 changes: 56 additions & 0 deletions src/database/migrations/2023_09_20_040645_add_indexes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->string('category')->nullable(false)->change();
$table->unique('category');
});

Schema::table('comments', function (Blueprint $table) {
$table->index(['post_id']);
});

Schema::table('posts', function (Blueprint $table) {
$table->index(['category_id']);
$table->index(['user_id']);
});

Schema::table('users', function (Blueprint $table) {
$table->index(['name']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->dropUnique(['category']);
$table->string('category')->nullable(true)->change();
});

Schema::table('comments', function (Blueprint $table) {
$table->dropIndex('comments_post_id_index');
});

Schema::table('posts', function (Blueprint $table) {
$table->dropIndex('posts_category_id_index');
$table->dropIndex('posts_user_id_index');
});

Schema::table('users', function (Blueprint $table) {
$table->dropIndex('users_name_index');
});
}
};
2 changes: 1 addition & 1 deletion src/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ seed:
# Sets up and spins up the project for the first time
setup:
#!/usr/bin/env bash
bash <(curl -s https://gist.githubusercontent.com/Justintime50/2de9303a491c22627ee502aaa7b1f289/raw/) glass glass has_database
bash <(curl -s https://gist.githubusercontent.com/Justintime50/2de9303a491c22627ee502aaa7b1f289/raw) glass glass has_database
# Tests the project
test:
Expand Down
8 changes: 4 additions & 4 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@sindresorhus/slugify": "^1.1",
"axios": "^1.3",
"bootstrap": "^5.2",
"bootstrap": "^5.3.2",
"laravel-vite-plugin": "^0.7.4",
"highlight.js": "^11.8",
"pineapple-library": "^3.2",
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/create-post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<input type='text' class='form-control' name='slug' id="slug" value="{{ old('slug') }}">

<label for="published">Post Status</label>
<select class="form-control" name="published">
<select class="form-select" name="published">
<option value="1" @if (old('published') == '1') {{ 'selected' }} @endif>Published</option>
<option value="0" @if (old('published') == '0') {{ 'selected' }} @endif>Draft</option>
</select>
Expand Down Expand Up @@ -49,7 +49,7 @@
</div>

<label for="category_id">Category</label>
<select class="form-control" name="category_id">
<select class="form-select" name="category_id">
@foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->category }}</option>
@endforeach
Expand Down
6 changes: 1 addition & 5 deletions src/resources/views/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
<i class="fas fa-clock"></i>
{{ \App\Http\Controllers\PostController::generateReadingTime($post) }} minutes
<i class="fas fa-tag"></i>
@if (isset($post->category->category))
<a href="{{ '/posts/category/' . $post->category->category }}">{{ $post->category->category }}</a>
@else
{{ 'Uncategorized' }}
@endif
<a href="{{ '/posts/category/' . $post->category->category }}">{{ $post->category->category }}</a>
</p>
<div class="banner-image-container">
@if (isset($post->banner_image_url) &&
Expand Down
6 changes: 1 addition & 5 deletions src/resources/views/posts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ class="banner-image">
<i class="fas fa-clock"></i>
{{ \App\Http\Controllers\PostController::generateReadingTime($post) }} minutes
<i class="fas fa-tag"></i>
@if (isset($post->category->category))
{{ $post->category->category }}
@else
{{ 'Uncategorized' }}
@endif
{{ $post->category->category }}
</p>
<p>
<?php $strippedPost = preg_replace("/[^0-9a-zA-Z_.!?' \r\n+]/", '', $post->post); ?>
Expand Down
33 changes: 22 additions & 11 deletions src/resources/views/rss/feed.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
<?=
'<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL
?>
'<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<rss version="2.0">
<channel>
<title><![CDATA[ {{ config('app.name') }} ]]></title>
<link><![CDATA[ {{ config('app.url') }} ]]></link>
<description><![CDATA[ Minimalist blog featuring syntax highlighting, images, comments, themes, and SEO out of the box. ]]></description>
<title>
<![CDATA[ {{ config('app.name') }} ]]>
</title>
<link>
<![CDATA[ {{ config('app.url') }} ]]>
</link>
<description>
<![CDATA[ Minimalist blog featuring syntax highlighting, images, comments, themes, and SEO out of the box. ]]>
</description>
<language>en</language>
<pubDate>{{ now() }}</pubDate>

@foreach($posts as $post)
@foreach ($posts as $post)
<item>
<title><![CDATA[{{ $post->title }}]]></title>
<link>{{ url('/'.str_replace(' ','-',$post->user->name).'/'.$post->slug) }}</link>
<description><![CDATA[{!! $post->post !!}]]></description>
<category>@if (isset($post->category->category)) {{ $post->category->category }} @else {{ 'Uncategorized' }} @endif</category>
<author><![CDATA[{{ $post->user->name }}]]></author>
<title>
<![CDATA[{{ $post->title }}]]>
</title>
<link>{{ url('/' . str_replace(' ', '-', $post->user->name) . '/' . $post->slug) }}</link>
<description>
<![CDATA[{!! $post->post !!}]]>
</description>
<category>{{ $post->category->category }}</category>
<author>
<![CDATA[{{ $post->user->name }}]]>
</author>
<pubDate>{{ $post->created_at->toRssString() }}</pubDate>
</item>
@endforeach
Expand Down

0 comments on commit dd59d29

Please sign in to comment.