add blog posts to database
This commit is contained in:
35
migrations/Version20250522212213.php
Normal file
35
migrations/Version20250522212213.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250522212213 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE blog_post (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, slug VARCHAR(255) NOT NULL, published_date DATE NOT NULL, updated_date DATE DEFAULT NULL, content CLOB NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(1024) NOT NULL)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
DROP TABLE blog_post
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
63
migrations/Version20250522212300.php
Normal file
63
migrations/Version20250522212300.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
final class Version20250522212300 extends AbstractMigration
|
||||
{
|
||||
private const BLOG_POST_SLUGS = [
|
||||
'doctor_who_gayness_church',
|
||||
'does_resurrection_ground_works',
|
||||
'easter',
|
||||
'euhwc_toast_to_the_lasses_2024',
|
||||
'god_is_not_great',
|
||||
'llms_do_not_understand_anything',
|
||||
'my_feed_and_reading_list',
|
||||
'no_more_youtube',
|
||||
'open_questions_about_sex',
|
||||
'paradox',
|
||||
'sapiens_on_religion',
|
||||
'science_and_philosophy',
|
||||
'surprised_by_hope',
|
||||
'tracking_pixels',
|
||||
'who_consecrates_the_temple',
|
||||
'word_hallucination_with_reference_to_llms',
|
||||
];
|
||||
|
||||
public function getDescription(): string {
|
||||
return 'Migrating my blog posts from my old website to notes in my new website';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void {
|
||||
foreach (self::BLOG_POST_SLUGS as $slug) {
|
||||
$blogPostPath = 'scripts/blog-migrated/' . $slug . '.yaml';
|
||||
$blogPost = Yaml::parseFile($blogPostPath);
|
||||
|
||||
$publishedDate = $blogPost['pubDate'];
|
||||
$updatedDate = array_key_exists(array: $blogPost, key: 'updatedDate')
|
||||
? $blogPost['updatedDate']
|
||||
: null;
|
||||
$title = str_replace("'", "''", $blogPost['title']);
|
||||
$description = str_replace("'", "''", $blogPost['description']);
|
||||
$content = str_replace("'", "''", $blogPost['content']);
|
||||
|
||||
$this->addSql(<<<SQL
|
||||
INSERT INTO blog_post(slug, published_date, updated_date, title, description, content)
|
||||
VALUES('$slug', '$publishedDate', '$updatedDate', '$title', '$description', '$content')
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void {
|
||||
foreach (self::BLOG_POST_SLUGS as $slug) {
|
||||
$this->addSql(<<<SQL
|
||||
DELETE FROM blog_post WHERE slug = '$slug'
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
92
src/Entity/BlogPost.php
Normal file
92
src/Entity/BlogPost.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\BlogPostRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: BlogPostRepository::class)]
|
||||
class BlogPost
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $slug = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
private ?\DateTime $publishedDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
private ?\DateTime $updatedDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
private ?string $content = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(length: 1024)]
|
||||
private ?string $description = null;
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSlug(): ?string {
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function setSlug(string $slug): static {
|
||||
$this->slug = $slug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPublishedDate(): ?\DateTime {
|
||||
return $this->publishedDate;
|
||||
}
|
||||
|
||||
public function setPublishedDate(\DateTime $publishedDate): static {
|
||||
$this->publishedDate = $publishedDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUpdatedDate(): ?\DateTime {
|
||||
return $this->updatedDate;
|
||||
}
|
||||
|
||||
public function setUpdatedDate(?\DateTime $updatedDate): static {
|
||||
$this->updatedDate = $updatedDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent(): ?string {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent(string $content): static {
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): static {
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): static {
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
17
src/Repository/BlogPostRepository.php
Normal file
17
src/Repository/BlogPostRepository.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\BlogPost;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<BlogPost>
|
||||
*/
|
||||
class BlogPostRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry) {
|
||||
parent::__construct($registry, BlogPost::class);
|
||||
}
|
||||
}
|
||||
2
todo.txt
2
todo.txt
@@ -1,8 +1,6 @@
|
||||
Tidy up notes index page to match existing links index page
|
||||
Make BlogPost entity
|
||||
Add blog post page
|
||||
Add blog index page
|
||||
Write an SQL script to insert all blog posts from existing website
|
||||
Add a most recent blog post to my home page
|
||||
Add a most recent note to my home page
|
||||
Write a script to take a database dump
|
||||
|
||||
Reference in New Issue
Block a user