fix(migrations): ensure safe migration steps for doctor_expertise and doctor_cities, drop legacy tables conditionally

This commit is contained in:
hamed
2026-06-28 09:32:27 +03:30
parent e966e11807
commit 90a908c503
3 changed files with 83 additions and 16 deletions
+23 -2
View File
@@ -22,8 +22,29 @@ final class Version20260611075829 extends AbstractMigration
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE user_active_context (db_uuid VARCHAR(36) NOT NULL, updated_at INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY (user_id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE user_active_context ADD CONSTRAINT FK_A94E639A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE');
$this->addSql('DROP TABLE site_config');
$this->addSql('ALTER TABLE appointments DROP booked_by, DROP commission_rials');
// On a fresh DB site_config does not exist yet (it is created later by
// Version20260611083424). IF EXISTS keeps this a no-op on fresh installs
// while still dropping the legacy table on older drifted databases.
$this->addSql('DROP TABLE IF EXISTS site_config');
// appointments.booked_by / commission_rials are never created by any
// migration — they only exist on older drifted dev DBs. Drop them only
// if present so a fresh DB doesn't fail with errno 1091.
$this->addSql('DROP PROCEDURE IF EXISTS __mig_075829');
$this->addSql(<<<'SQL'
CREATE PROCEDURE __mig_075829()
BEGIN
DECLARE db VARCHAR(64); SET db = DATABASE();
IF EXISTS (SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = db AND TABLE_NAME = 'appointments' AND COLUMN_NAME = 'booked_by') THEN
ALTER TABLE appointments DROP booked_by;
END IF;
IF EXISTS (SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = db AND TABLE_NAME = 'appointments' AND COLUMN_NAME = 'commission_rials') THEN
ALTER TABLE appointments DROP commission_rials;
END IF;
END
SQL);
$this->addSql('CALL __mig_075829()');
$this->addSql('DROP PROCEDURE __mig_075829');
}
public function down(Schema $schema): void