evwiki/migrations/Version20250601120221.php
2025-06-02 06:37:37 +02:00

82 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250601120221 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add car models, revisions, properties, and embeddings tables';
}
public function up(Schema $schema): void
{
// Enable pgvector extension
$this->addSql('CREATE EXTENSION IF NOT EXISTS vector');
// Create brands table
$this->addSql('CREATE TABLE brands (
id VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)');
// Create car_models table
$this->addSql('CREATE TABLE car_models (
id VARCHAR(255) NOT NULL,
brand_id VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)');
// Create car_revisions table
$this->addSql('CREATE TABLE car_revisions (
id VARCHAR(255) NOT NULL,
car_model_id VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)');
// Create car_properties table
$this->addSql('CREATE TABLE car_properties (
id VARCHAR(255) NOT NULL,
car_revision_id VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY(id)
)');
// Create embeddings table
$this->addSql('CREATE TABLE embeddings (
id VARCHAR(255) NOT NULL,
phrase_hash VARCHAR(255) NOT NULL,
phrase VARCHAR(255) NOT NULL,
large_embedding_vector VECTOR(3072) NOT NULL,
small_embedding_vector VECTOR(1536) NOT NULL,
PRIMARY KEY(id)
)');
// Add foreign key constraints
$this->addSql('ALTER TABLE car_models ADD CONSTRAINT FK_car_models_brand_id FOREIGN KEY (brand_id) REFERENCES brands (id)');
$this->addSql('ALTER TABLE car_revisions ADD CONSTRAINT FK_car_revisions_car_model_id FOREIGN KEY (car_model_id) REFERENCES car_models (id)');
$this->addSql('ALTER TABLE car_properties ADD CONSTRAINT FK_car_properties_car_revision_id FOREIGN KEY (car_revision_id) REFERENCES car_revisions (id)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE car_properties');
$this->addSql('DROP TABLE car_revisions');
$this->addSql('DROP TABLE car_models');
$this->addSql('DROP TABLE embeddings');
$this->addSql('DROP TABLE brands');
}
}