mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-16 15:19:34 +00:00
Umstellung Migrationen bzgl. Multi-Plattform-Support.
Zunächst MySQL, SQLite Statements integrieren.
This commit is contained in:
parent
7162199e61
commit
18a290bd67
2 changed files with 284 additions and 6 deletions
|
|
@ -4,20 +4,298 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace DoctrineMigrations;
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use App\Migration\AbstractMultiPlatformMigration;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
|
||||||
|
|
||||||
final class Version20250325073036 extends AbstractMigration
|
final class Version20250325073036 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
public function up(Schema $schema): void
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE categories ADD part_ipn_prefix VARCHAR(255) NOT NULL AFTER partname_regex');
|
return 'Add part_ipn_prefix column to categories table and remove unique constraint from parts table';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mySQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE categories ADD COLUMN part_ipn_prefix VARCHAR(255) NOT NULL DEFAULT \'\'');
|
||||||
$this->addSql('DROP INDEX UNIQ_6940A7FE3D721C14 ON parts');
|
$this->addSql('DROP INDEX UNIQ_6940A7FE3D721C14 ON parts');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
public function mySQLDown(Schema $schema): void
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE `categories` DROP part_ipn_prefix');
|
$this->addSql('ALTER TABLE `categories` DROP part_ipn_prefix');
|
||||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON `parts` (ipn)');
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON `parts` (ipn)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sqLiteUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__categories AS
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
FROM categories
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE categories');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE categories (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
parent_id INTEGER DEFAULT NULL,
|
||||||
|
id_preview_attachment INTEGER DEFAULT NULL,
|
||||||
|
partname_hint CLOB NOT NULL,
|
||||||
|
partname_regex CLOB NOT NULL,
|
||||||
|
part_ipn_prefix VARCHAR(255) DEFAULT '' NOT NULL,
|
||||||
|
disable_footprints BOOLEAN NOT NULL,
|
||||||
|
disable_manufacturers BOOLEAN NOT NULL,
|
||||||
|
disable_autodatasheets BOOLEAN NOT NULL,
|
||||||
|
disable_properties BOOLEAN NOT NULL,
|
||||||
|
default_description CLOB NOT NULL,
|
||||||
|
default_comment CLOB NOT NULL,
|
||||||
|
comment CLOB NOT NULL,
|
||||||
|
not_selectable BOOLEAN NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
alternative_names CLOB DEFAULT NULL,
|
||||||
|
eda_info_reference_prefix VARCHAR(255) DEFAULT NULL,
|
||||||
|
eda_info_invisible BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_bom BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_board BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_sim BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_kicad_symbol VARCHAR(255) DEFAULT NULL,
|
||||||
|
CONSTRAINT FK_3AF34668727ACA70 FOREIGN KEY (parent_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE,
|
||||||
|
CONSTRAINT FK_3AF34668EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO categories (
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
) SELECT
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
FROM __temp__categories
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE __temp__categories');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_3AF34668727ACA70 ON categories (parent_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_3AF34668EA7100A1 ON categories (id_preview_attachment)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX category_idx_name ON categories (name)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX category_idx_parent_name ON categories (parent_id, name)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sqLiteDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__categories AS
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
FROM categories
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE categories');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE categories (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
parent_id INTEGER DEFAULT NULL,
|
||||||
|
id_preview_attachment INTEGER DEFAULT NULL,
|
||||||
|
partname_hint CLOB NOT NULL,
|
||||||
|
partname_regex CLOB NOT NULL,
|
||||||
|
disable_footprints BOOLEAN NOT NULL,
|
||||||
|
disable_manufacturers BOOLEAN NOT NULL,
|
||||||
|
disable_autodatasheets BOOLEAN NOT NULL,
|
||||||
|
disable_properties BOOLEAN NOT NULL,
|
||||||
|
default_description CLOB NOT NULL,
|
||||||
|
default_comment CLOB NOT NULL,
|
||||||
|
comment CLOB NOT NULL,
|
||||||
|
not_selectable BOOLEAN NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
alternative_names CLOB DEFAULT NULL,
|
||||||
|
eda_info_reference_prefix VARCHAR(255) DEFAULT NULL,
|
||||||
|
eda_info_invisible BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_bom BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_board BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_exclude_from_sim BOOLEAN DEFAULT NULL,
|
||||||
|
eda_info_kicad_symbol VARCHAR(255) DEFAULT NULL,
|
||||||
|
CONSTRAINT FK_3AF34668727ACA70 FOREIGN KEY (parent_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE,
|
||||||
|
CONSTRAINT FK_3AF34668EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO categories (
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
) SELECT
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
id_preview_attachment,
|
||||||
|
partname_hint,
|
||||||
|
partname_regex,
|
||||||
|
disable_footprints,
|
||||||
|
disable_manufacturers,
|
||||||
|
disable_autodatasheets,
|
||||||
|
disable_properties,
|
||||||
|
default_description,
|
||||||
|
default_comment,
|
||||||
|
comment,
|
||||||
|
not_selectable,
|
||||||
|
name,
|
||||||
|
last_modified,
|
||||||
|
datetime_added,
|
||||||
|
alternative_names,
|
||||||
|
eda_info_reference_prefix,
|
||||||
|
eda_info_invisible,
|
||||||
|
eda_info_exclude_from_bom,
|
||||||
|
eda_info_exclude_from_board,
|
||||||
|
eda_info_exclude_from_sim,
|
||||||
|
eda_info_kicad_symbol
|
||||||
|
FROM __temp__categories
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE __temp__categories');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_3AF34668727ACA70 ON categories (parent_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_3AF34668EA7100A1 ON categories (id_preview_attachment)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX category_idx_name ON categories (name)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX category_idx_parent_name ON categories (parent_id, name)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
//Not needed
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
//Not needed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ class Category extends AbstractPartsContainingDBElement
|
||||||
* @var string The prefix for ipn generation for created parts in this category.
|
* @var string The prefix for ipn generation for created parts in this category.
|
||||||
*/
|
*/
|
||||||
#[Groups(['full', 'import', 'category:read', 'category:write'])]
|
#[Groups(['full', 'import', 'category:read', 'category:write'])]
|
||||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: false, options: ['default' => ''])]
|
||||||
protected string $part_ipn_prefix = '';
|
protected string $part_ipn_prefix = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue