Files
clinicpro/migrations/Version20260719044321.php
T
hamed a4b07c2f80 feat(blog): add city_id to blogs for city-specific scoping
- Introduced a new nullable city_id column in the blogs table to allow scoping of blog posts to specific cities.
- Updated Blog entity to include a ManyToOne relationship with the City entity.
- Enhanced BlogController to handle city_id in the request, allowing filtering of posts by city.
- Modified BlogRepository to support querying published posts based on city_id.
- Added tests to ensure correct behavior for city-scoped and nationwide posts, including creation and updating of posts with city associations.
2026-07-19 08:23:57 +03:30

43 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Blog posts get an optional city so the multi-domain public site can scope them.
* NULL is a permanent, meaningful state: a nationwide post, canonical on the main
* domain and listed on every city domain.
*
* Existing rows become nationwide, which preserves current behaviour.
*
* Note: doctrine:migrations:diff also wanted to alter date_overrides,
* patient_sessions, wallet_transactions and weekly_schedules. That is
* pre-existing drift between the entities and the database, unrelated to this
* feature, so it is deliberately left out rather than bundled in here.
*/
final class Version20260719044321 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add nullable blogs.city_id (NULL = nationwide post)';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE blogs ADD city_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE blogs ADD CONSTRAINT FK_F41BCA708BAC62AF FOREIGN KEY (city_id) REFERENCES cities (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX idx_blogs_city ON blogs (city_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE blogs DROP FOREIGN KEY FK_F41BCA708BAC62AF');
$this->addSql('DROP INDEX idx_blogs_city ON blogs');
$this->addSql('ALTER TABLE blogs DROP city_id');
}
}