Files
clinicpro/migrations/Version20260802113956.php
hamedandClaude Opus 5 dd284ec622 refactor(branch): remove the branch domain, keep the address
Branches and rooms are not part of the resource-first product: a room is a
resource like any other, and the only thing the branch pages still managed —
opening hours — duplicated the resource's own shift.

What could not go is the address. Every appointment carries address_id (75 of
75 rows), the public booking site reads /clinic-pro/doctor-address/{id}, and a
resource derives its tenant pair from the address it belongs to. So
DoctorAddress stays as an invisible anchor with no page and no menu entry, and
GET /api/v1/addresses replaces GET /api/v1/branches for the forms that still
need to say "where".

BranchResolver was likewise not a branch feature. doctor_addresses is a global
table, so TenantFilter does not cover it and eight callers across booking,
availability, pricing and the catalog went through this resolver to avoid
leaking another clinic's address. It moved to Doctor\Service\AddressResolver
rather than dying with the domain.

The availability engine loses one layer: a resource's real hours were the
branch hours intersected with its shift, and are now the shift alone. That is
the single behavioural change, and the three tests that asserted the old
contract are replaced by one that states the new one.

Rooms already had a resource row each; the migration drops only the bridge
back to `rooms`, and drops it before the table — that foreign key is ON DELETE
CASCADE and the other order would take the resources, and their appointments,
with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 15:25:32 +03:30

51 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Drops the Branch domain: rooms and branch working hours.
*
* A room stays visible to the user as a *resource* — `clinic_resources` already has a
* row per room, and only its bridge back to `rooms` goes away. That bridge is dropped
* before the tables, because `clinic_resources.room_id` is ON DELETE CASCADE and
* dropping `rooms` first would take those resources — and their appointments — with it.
*/
final class Version20260802113956 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove the branch domain (rooms, branch working hours); rooms live on as plain resources';
}
public function up(Schema $schema): void
{
// اول پل منبع→اتاق، بعد خودِ جدول‌ها. برعکسش یعنی CASCADE منابع را هم می‌برد.
$this->addSql('ALTER TABLE clinic_resources DROP FOREIGN KEY `FK_10DABCC554177093`');
$this->addSql('DROP INDEX uniq_resource_room ON clinic_resources');
$this->addSql('ALTER TABLE clinic_resources DROP room_id');
$this->addSql('ALTER TABLE branch_working_hours DROP FOREIGN KEY `FK_E8C43E37F5B7AF75`');
$this->addSql('ALTER TABLE rooms DROP FOREIGN KEY `FK_7CA11A96F5B7AF75`');
$this->addSql('DROP TABLE IF EXISTS branch_working_hours');
$this->addSql('DROP TABLE IF EXISTS rooms');
}
public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE branch_working_hours (id INT AUTO_INCREMENT NOT NULL, day_of_week SMALLINT NOT NULL, sequence SMALLINT DEFAULT 0 NOT NULL, start_minute SMALLINT NOT NULL, end_minute SMALLINT NOT NULL, active TINYINT DEFAULT 1 NOT NULL, entity_type VARCHAR(10) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_520_ci`, entity_id INT NOT NULL, address_id INT NOT NULL, INDEX idx_bwh_tenant (entity_type, entity_id), INDEX idx_bwh_address_day (address_id, day_of_week, active), INDEX IDX_E8C43E37F5B7AF75 (address_id), UNIQUE INDEX uniq_bwh_address_day_seq (address_id, day_of_week, sequence), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE rooms (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_520_ci`, name VARCHAR(120) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_520_ci`, room_type VARCHAR(60) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_520_ci`, capacity SMALLINT DEFAULT 1 NOT NULL, floor VARCHAR(20) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_520_ci`, active TINYINT DEFAULT 1 NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, entity_type VARCHAR(10) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_520_ci`, entity_id INT NOT NULL, address_id INT NOT NULL, UNIQUE INDEX UNIQ_7CA11A96D17F50A6 (uuid), INDEX IDX_7CA11A96F5B7AF75 (address_id), INDEX idx_rooms_address (address_id, active), INDEX idx_rooms_tenant (entity_type, entity_id, active), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE branch_working_hours ADD CONSTRAINT `FK_E8C43E37F5B7AF75` FOREIGN KEY (address_id) REFERENCES doctor_addresses (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE rooms ADD CONSTRAINT `FK_7CA11A96F5B7AF75` FOREIGN KEY (address_id) REFERENCES doctor_addresses (id) ON DELETE CASCADE');
// ردیف‌های اتاق برنمی‌گردند؛ ستون و قیدش برمی‌گردد تا اسکیمای قبلی بازسازی شود.
$this->addSql('ALTER TABLE clinic_resources ADD room_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE clinic_resources ADD CONSTRAINT `FK_10DABCC554177093` FOREIGN KEY (room_id) REFERENCES rooms (id) ON DELETE CASCADE');
$this->addSql('CREATE UNIQUE INDEX uniq_resource_room ON clinic_resources (room_id)');
}
}