This repository has been archived on 2025-06-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
joeac.net-symfony/symfony/migrations/Version20250522212300.php
2025-06-03 07:27:19 +01:00

69 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use DateTime;
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);
$publishedDateTime = DateTime::createFromFormat('U', strval($blogPost['pubDate']));
$publishedDate = $publishedDateTime->format('Y-m-d');
$updatedDateTime = array_key_exists(array: $blogPost, key: 'updatedDate')
? DateTime::createFromFormat('U', strval($blogPost['updatedDate']))
: null;
$updatedDate = $updatedDateTime == null
? 'NULL'
: "'" . $updatedDateTime->format('Y-m-d') . "'";
$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);
}
}
}