add blog posts to database
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user