Files
symfony-k3s/migrations/Version20260811150000.php
T

35 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260811150000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add user weather settings, cached daily forecasts, and task weather metadata.';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE settings (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, latitude NUMERIC(10, 7) DEFAULT NULL, longitude NUMERIC(10, 7) DEFAULT NULL, location_updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_SETTINGS_USER (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE weather_forecast (id INT AUTO_INCREMENT NOT NULL, settings_id INT NOT NULL, forecast_date DATE NOT NULL, temperature_max DOUBLE PRECISION DEFAULT NULL, temperature_min DOUBLE PRECISION DEFAULT NULL, precipitation_sum DOUBLE PRECISION DEFAULT NULL, precipitation_probability_max INT DEFAULT NULL, rain_sum DOUBLE PRECISION DEFAULT NULL, weather_code INT DEFAULT NULL, fetched_at DATETIME NOT NULL, INDEX IDX_FORECAST_SETTINGS (settings_id), UNIQUE INDEX weather_forecast_settings_day (settings_id, forecast_date), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE settings ADD CONSTRAINT FK_SETTINGS_USER FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE weather_forecast ADD CONSTRAINT FK_FORECAST_SETTINGS FOREIGN KEY (settings_id) REFERENCES settings (id) ON DELETE CASCADE');
$this->addSql("ALTER TABLE task ADD is_outdoor TINYINT(1) NOT NULL DEFAULT 0, ADD weather_profile VARCHAR(30) NOT NULL DEFAULT 'none'");
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE weather_forecast DROP FOREIGN KEY FK_FORECAST_SETTINGS');
$this->addSql('ALTER TABLE settings DROP FOREIGN KEY FK_SETTINGS_USER');
$this->addSql('DROP TABLE weather_forecast');
$this->addSql('DROP TABLE settings');
$this->addSql('ALTER TABLE task DROP is_outdoor, DROP weather_profile');
}
}