mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-19 09:51:45 +00:00
Überprüfung auf Tabellenexistenz in Migration hinzufügen.
This commit is contained in:
parent
e4cd243c7c
commit
dde91ff1c5
2 changed files with 209 additions and 187 deletions
|
|
@ -16,6 +16,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
|
|
||||||
public function mySQLUp(Schema $schema): void
|
public function mySQLUp(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
if (!$this->doesTableExist('assemblies')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assemblies (
|
CREATE TABLE assemblies (
|
||||||
id INT AUTO_INCREMENT NOT NULL,
|
id INT AUTO_INCREMENT NOT NULL,
|
||||||
|
|
@ -47,7 +48,9 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
ALTER TABLE assemblies
|
ALTER TABLE assemblies
|
||||||
ADD CONSTRAINT FK_5F3832C0EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES `attachments` (id) ON DELETE SET NULL
|
ADD CONSTRAINT FK_5F3832C0EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES `attachments` (id) ON DELETE SET NULL
|
||||||
SQL);
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->doesTableExist('assembly_bom_entries')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assembly_bom_entries (
|
CREATE TABLE assembly_bom_entries (
|
||||||
id INT AUTO_INCREMENT NOT NULL,
|
id INT AUTO_INCREMENT NOT NULL,
|
||||||
|
|
@ -87,6 +90,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
ADD CONSTRAINT FK_8C74887E3FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id)
|
ADD CONSTRAINT FK_8C74887E3FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id)
|
||||||
SQL);
|
SQL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function mySQLDown(Schema $schema): void
|
public function mySQLDown(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
|
@ -96,6 +100,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
|
|
||||||
public function sqLiteUp(Schema $schema): void
|
public function sqLiteUp(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
if (!$this->doesTableExist('assemblies')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assemblies (
|
CREATE TABLE assemblies (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
|
@ -120,7 +125,9 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX IDX_5F3832C0EA7100A1 ON assemblies (id_preview_attachment)');
|
$this->addSql('CREATE INDEX IDX_5F3832C0EA7100A1 ON assemblies (id_preview_attachment)');
|
||||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_5F3832C03D721C14 ON assemblies (ipn)');
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_5F3832C03D721C14 ON assemblies (ipn)');
|
||||||
$this->addSql('CREATE INDEX assembly_idx_ipn ON assemblies (ipn)');
|
$this->addSql('CREATE INDEX assembly_idx_ipn ON assemblies (ipn)');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->doesTableExist('assembly_bom_entries')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assembly_bom_entries (
|
CREATE TABLE assembly_bom_entries (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
|
@ -147,6 +154,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX IDX_8C74887E22522999 ON assembly_bom_entries (id_referenced_assembly)');
|
$this->addSql('CREATE INDEX IDX_8C74887E22522999 ON assembly_bom_entries (id_referenced_assembly)');
|
||||||
$this->addSql('CREATE INDEX IDX_8C74887E3FFDCD60 ON assembly_bom_entries (price_currency_id)');
|
$this->addSql('CREATE INDEX IDX_8C74887E3FFDCD60 ON assembly_bom_entries (price_currency_id)');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function sqLiteDown(Schema $schema): void
|
public function sqLiteDown(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
|
@ -156,6 +164,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
|
|
||||||
public function postgreSQLUp(Schema $schema): void
|
public function postgreSQLUp(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
if (!$this->doesTableExist('assemblies')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assemblies (
|
CREATE TABLE assemblies (
|
||||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
|
@ -187,7 +196,9 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
ALTER TABLE assemblies
|
ALTER TABLE assemblies
|
||||||
ADD CONSTRAINT FK_5F3832C0EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
|
ADD CONSTRAINT FK_5F3832C0EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
|
||||||
SQL);
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->doesTableExist('assembly_bom_entries')) {
|
||||||
$this->addSql(<<<'SQL'
|
$this->addSql(<<<'SQL'
|
||||||
CREATE TABLE assembly_bom_entries (
|
CREATE TABLE assembly_bom_entries (
|
||||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
|
@ -227,6 +238,7 @@ final class Version20251016141941 extends AbstractMultiPlatformMigration
|
||||||
ADD CONSTRAINT FK_8C74887E3FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE
|
ADD CONSTRAINT FK_8C74887E3FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE
|
||||||
SQL);
|
SQL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function postgreSQLDown(Schema $schema): void
|
public function postgreSQLDown(Schema $schema): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,16 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration
|
||||||
return $result > 0;
|
return $result > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a table exists in the database.
|
||||||
|
* @return bool Returns true, if the table exists
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function doesTableExist(string $table): bool
|
||||||
|
{
|
||||||
|
return $this->connection->createSchemaManager()->tablesExist([$table]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a column exists in a table.
|
* Checks if a column exists in a table.
|
||||||
* @return bool Returns true, if the column exists
|
* @return bool Returns true, if the column exists
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue