-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(matching): introduce product matching engine
Uses part of the https://schema.org vocabulary. Make use of the api platform schema generator to bootstrap entities. > resolves #448
- Loading branch information
1 parent
03b4f84
commit 26777a3
Showing
16 changed files
with
695 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
id: | ||
generate: true | ||
|
||
namespaces: | ||
entity: "App\\Entity" | ||
|
||
|
||
# The list of types and properties we want to use | ||
types: | ||
Thing: | ||
embeddable: false | ||
properties: | ||
name: ~ | ||
alternateName: ~ | ||
description: ~ | ||
Product: | ||
parent: "Thing" | ||
embeddable: false | ||
properties: | ||
# Force the type of the property to text | ||
category: | ||
range: "Text" | ||
cardinality: "(0..1)" | ||
offers: | ||
range: "Offer" | ||
embedded: true | ||
columnPrefix: "offer_" | ||
cardinality: "(0..1)" | ||
Offer: | ||
# Disable the generation of the class hierarchy for this type | ||
parent: false | ||
embeddable: true | ||
properties: | ||
# Force the type of the addressCountry property to text | ||
availableAtOrFrom: | ||
range: "Text" | ||
cardinality: "(0..1)" | ||
price: | ||
range: "Number" | ||
cardinality: "(0..1)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Schema generator | ||
|
||
Some entities were bootstrapped using the api-platform schema-generator: | ||
https://api-platform.com/docs/schema-generator/ | ||
|
||
The generator uses the vocabulary formalized on [schema.org](https://schema.org). | ||
|
||
## Configuration | ||
|
||
[config/schema_generator.yaml](config/schema_generator.yaml) | ||
|
||
## Generation | ||
|
||
```shell | ||
docker-compose exec php vendor/bin/schema generate src/ config/schema_generator.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* On custom index and foreign key names: | ||
* https://stackoverflow.com/questions/7623958/naming-a-relation-in-doctrine-2-orm. | ||
*/ | ||
final class Version20210922155023 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name LONGTEXT DEFAULT NULL, alternate_name LONGTEXT DEFAULT NULL, description LONGTEXT DEFAULT NULL, category LONGTEXT DEFAULT NULL, offer_available_at_or_from LONGTEXT DEFAULT NULL, offer_price DOUBLE PRECISION DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE matching_context ADD product_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE matching_context ADD CONSTRAINT FK_matching_context_product_id FOREIGN KEY (product_id) REFERENCES product (id)'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_matching_context_product_id ON matching_context (product_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE matching_context DROP FOREIGN KEY FK_matching_context_product_id'); | ||
$this->addSql('DROP TABLE product'); | ||
$this->addSql('DROP INDEX UNIQ_matching_context_product_id ON matching_context'); | ||
$this->addSql('ALTER TABLE matching_context DROP product_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.