Made order and pricedetails timestampable.

Further the migration fixes the typos in attachment table names and filled empty timestamps with the current date.
This commit is contained in:
Jan Böhmer 2019-08-29 13:06:04 +02:00
parent d79f580b30
commit 1776cd9a77
6 changed files with 115 additions and 28 deletions

View file

@ -33,7 +33,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* Class Attachment. * Class Attachment.
* *
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="`attachements`") * @ORM\Table(name="`attachments`")
* @ORM\InheritanceType("SINGLE_TABLE") * @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="class_name", type="string") * @ORM\DiscriminatorColumn(name="class_name", type="string")
* @ORM\DiscriminatorMap({"PartDB\Part" = "PartAttachment", "Part" = "PartAttachment"}) * @ORM\DiscriminatorMap({"PartDB\Part" = "PartAttachment", "Part" = "PartAttachment"})

View file

@ -61,7 +61,7 @@ use Doctrine\ORM\Mapping as ORM;
* Class AttachmentType. * Class AttachmentType.
* *
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") * @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
* @ORM\Table(name="`attachement_types`") * @ORM\Table(name="`attachment_types`")
*/ */
class AttachmentType extends StructuralDBElement class AttachmentType extends StructuralDBElement
{ {

View file

@ -243,6 +243,12 @@ class Part extends AttachmentContainingDBElement
*/ */
protected $manufacturer_product_number = ''; protected $manufacturer_product_number = '';
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $manufacturing_status;
/** /**
* @var bool Determines if this part entry needs review (for example, because it is work in progress) * @var bool Determines if this part entry needs review (for example, because it is work in progress)
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")

View file

@ -62,20 +62,25 @@ declare(strict_types=1);
namespace App\Entity\PriceInformations; namespace App\Entity\PriceInformations;
use App\Entity\Base\DBElement; use App\Entity\Base\DBElement;
use App\Entity\Base\TimestampTrait;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier; use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\PersistentCollection;
use Exception; use Exception;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* Class Orderdetail. * Class Orderdetail.
* *
* @ORM\Table("`orderdetails`") * @ORM\Table("`orderdetails`")
* @ORM\Entity() * @ORM\Entity()
* @ORM\HasLifecycleCallbacks()
*/ */
class Orderdetail extends DBElement class Orderdetail extends DBElement
{ {
use TimestampTrait;
/** /**
* @var Part * @var Part
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails")
@ -99,25 +104,20 @@ class Orderdetail extends DBElement
* @var string * @var string
* @ORM\Column(type="string") * @ORM\Column(type="string")
*/ */
protected $supplierpartnr; protected $supplierpartnr = "";
/** /**
* @var bool * @var bool
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
*/ */
protected $obsolete; protected $obsolete = false;
/** /**
* @var string * @var string
* @ORM\Column(type="string") * @ORM\Column(type="string")
* @Assert\Url()
*/ */
protected $supplier_product_url; protected $supplier_product_url = "";
/**
* @var \DateTime The date when this element was created.
* @ORM\Column(type="datetimetz", name="datetime_added")
*/
protected $addedDate;
/** /**
* Returns the ID as an string, defined by the element class. * Returns the ID as an string, defined by the element class.
@ -151,7 +151,7 @@ class Orderdetail extends DBElement
* *
* @return Supplier the supplier of this orderdetails * @return Supplier the supplier of this orderdetails
*/ */
public function getSupplier(): Supplier public function getSupplier(): ?Supplier
{ {
return $this->supplier; return $this->supplier;
} }
@ -180,17 +180,6 @@ class Orderdetail extends DBElement
return (bool) $this->obsolete; return (bool) $this->obsolete;
} }
/**
* Returns the date/time when the element was created.
* Returns null if the element was not yet saved to DB yet.
*
* @return \DateTime|null The creation time of the part.
*/
public function getAddedDate(): ?\DateTime
{
return $this->addedDate;
}
/** /**
* Get the link to the website of the article on the suppliers website. * Get the link to the website of the article on the suppliers website.
* *

View file

@ -62,6 +62,7 @@ declare(strict_types=1);
namespace App\Entity\PriceInformations; namespace App\Entity\PriceInformations;
use App\Entity\Base\DBElement; use App\Entity\Base\DBElement;
use App\Entity\Base\TimestampTrait;
use App\Validator\Constraints\Selectable; use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@ -72,10 +73,14 @@ use Symfony\Component\Validator\Constraints as Assert;
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("`pricedetails`") * @ORM\Table("`pricedetails`")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields={"orderdetail", "min_discount_quantity"}) * @UniqueEntity(fields={"orderdetail", "min_discount_quantity"})
*/ */
class Pricedetail extends DBElement class Pricedetail extends DBElement
{ {
use TimestampTrait;
/** /**
* @var Orderdetail * @var Orderdetail
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails") * @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
@ -118,10 +123,6 @@ class Pricedetail extends DBElement
*/ */
protected $manual_input; protected $manual_input;
/**
* @ORM\Column(type="datetimetz")
*/
protected $last_modified;
/******************************************************************************** /********************************************************************************
* *
@ -303,6 +304,6 @@ class Pricedetail extends DBElement
*/ */
public function getIDString(): string public function getIDString(): string
{ {
return 'PD'.sprintf('%06d', $this->getID()); return 'PD' . sprintf('%06d', $this->getID());
} }
} }

View file

@ -0,0 +1,91 @@
<?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 Version20190829104643 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
//Add timestamps to orderdetails and pricedetails
$this->addSql('ALTER TABLE attachements CHANGE element_id element_id INT DEFAULT NULL, CHANGE type_id type_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE attachement_types CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE devices CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE device_parts CHANGE id_part id_part INT DEFAULT NULL, CHANGE id_device id_device INT DEFAULT NULL');
$this->addSql('ALTER TABLE categories CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE footprints CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE filename filename MEDIUMTEXT NOT NULL, CHANGE filename_3d filename_3d MEDIUMTEXT NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE manufacturers CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE measurement_units CHANGE unit unit VARCHAR(255) DEFAULT NULL, CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE measurement_units ADD CONSTRAINT FK_F5AF83CF727ACA70 FOREIGN KEY (parent_id) REFERENCES `measurement_units` (id)');
$this->addSql('CREATE INDEX IDX_F5AF83CF727ACA70 ON measurement_units (parent_id)');
$this->addSql('ALTER TABLE parts ADD manufacturing_status VARCHAR(255) DEFAULT NULL, CHANGE id_category id_category INT DEFAULT NULL, CHANGE id_footprint id_footprint INT DEFAULT NULL, CHANGE order_orderdetails_id order_orderdetails_id INT DEFAULT NULL, CHANGE id_manufacturer id_manufacturer INT DEFAULT NULL, CHANGE id_master_picture_attachement id_master_picture_attachement INT DEFAULT NULL, CHANGE id_part_unit id_part_unit INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE mass mass DOUBLE PRECISION DEFAULT NULL');
$this->addSql('ALTER TABLE part_lots CHANGE id_store_location id_store_location INT DEFAULT NULL, CHANGE id_part id_part INT DEFAULT NULL, CHANGE expiration_date expiration_date DATETIME DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE storelocations CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE storage_type_id storage_type_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE suppliers CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE default_currency_id default_currency_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE shipping_costs shipping_costs NUMERIC(11, 5) DEFAULT NULL');
$this->addSql('ALTER TABLE currencies CHANGE exchange_rate exchange_rate NUMERIC(11, 5) DEFAULT NULL, CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id)');
$this->addSql('CREATE INDEX IDX_37C44693727ACA70 ON currencies (parent_id)');
$this->addSql('ALTER TABLE orderdetails ADD last_modified DATETIME NOT NULL, CHANGE part_id part_id INT DEFAULT NULL, CHANGE id_supplier id_supplier INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE pricedetails ADD datetime_added DATETIME NOT NULL, CHANGE orderdetails_id orderdetails_id INT DEFAULT NULL, CHANGE id_currency id_currency INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE `groups` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE users CHANGE group_id group_id INT DEFAULT NULL, CHANGE password password VARCHAR(255) DEFAULT NULL, CHANGE first_name first_name VARCHAR(255) DEFAULT NULL, CHANGE last_name last_name VARCHAR(255) DEFAULT NULL, CHANGE department department VARCHAR(255) DEFAULT NULL, CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE config_language config_language VARCHAR(255) DEFAULT NULL, CHANGE config_timezone config_timezone VARCHAR(255) DEFAULT NULL, CHANGE config_theme config_theme VARCHAR(255) DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
//Fix typo in attachment table names
$this->addSql("ALTER TABLE attachements RENAME TO attachments;");
$this->addSql("ALTER TABLE attachement_types RENAME TO attachment_types;");
//Fill empty timestamps with current date
$tables = ["attachments", "attachment_types", "categories", "devices", "footprints", "manufacturers",
"orderdetails", "pricedetails", "storelocations"];
foreach ($tables as $table) {
$this->addSql("UPDATE $table SET datetime_added = NOW() WHERE datetime_added = '0000-00-00 00:00:00'");
$this->addSql("UPDATE $table SET last_modified = datetime_added WHERE last_modified = '0000-00-00 00:00:00'");
}
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE `attachement_types` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `attachements` CHANGE type_id type_id INT DEFAULT NULL, CHANGE element_id element_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `categories` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE currencies DROP FOREIGN KEY FK_37C44693727ACA70');
$this->addSql('DROP INDEX IDX_37C44693727ACA70 ON currencies');
$this->addSql('ALTER TABLE currencies CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE exchange_rate exchange_rate NUMERIC(11, 5) DEFAULT \'NULL\', CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `device_parts` CHANGE id_device id_device INT DEFAULT NULL, CHANGE id_part id_part INT DEFAULT NULL');
$this->addSql('ALTER TABLE `devices` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `footprints` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE filename filename MEDIUMTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE filename_3d filename_3d MEDIUMTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `groups` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `manufacturers` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `measurement_units` DROP FOREIGN KEY FK_F5AF83CF727ACA70');
$this->addSql('DROP INDEX IDX_F5AF83CF727ACA70 ON `measurement_units`');
$this->addSql('ALTER TABLE `measurement_units` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE unit unit VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8mb4_unicode_ci, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `orderdetails` DROP last_modified, CHANGE part_id part_id INT DEFAULT NULL, CHANGE id_supplier id_supplier INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE part_lots CHANGE id_store_location id_store_location INT DEFAULT NULL, CHANGE id_part id_part INT DEFAULT NULL, CHANGE expiration_date expiration_date DATETIME DEFAULT \'NULL\', CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `parts` DROP manufacturing_status, CHANGE id_category id_category INT DEFAULT NULL, CHANGE id_footprint id_footprint INT DEFAULT NULL, CHANGE id_manufacturer id_manufacturer INT DEFAULT NULL, CHANGE id_master_picture_attachement id_master_picture_attachement INT DEFAULT NULL, CHANGE order_orderdetails_id order_orderdetails_id INT DEFAULT NULL, CHANGE id_part_unit id_part_unit INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE mass mass DOUBLE PRECISION DEFAULT \'NULL\'');
$this->addSql('ALTER TABLE `pricedetails` DROP datetime_added, CHANGE orderdetails_id orderdetails_id INT DEFAULT NULL, CHANGE id_currency id_currency INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE `storelocations` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE storage_type_id storage_type_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `suppliers` CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE default_currency_id default_currency_id INT DEFAULT NULL, CHANGE shipping_costs shipping_costs NUMERIC(11, 5) DEFAULT \'NULL\', CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
$this->addSql('ALTER TABLE `users` CHANGE group_id group_id INT DEFAULT NULL, CHANGE password password VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE first_name first_name VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE last_name last_name VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE department department VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE email email VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE config_language config_language VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE config_timezone config_timezone VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE config_theme config_theme VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_general_ci, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');
}
}