Skip to content

Commit

Permalink
Change migration trait to deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGuilloux committed Jul 28, 2021
1 parent fb801cc commit a143b71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
30 changes: 25 additions & 5 deletions docs/Creation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The only way to create a new term is to make a migration. Since a term should always have at least one version, the migration will also create a version.

Hopefully, there is trait that might help you to do so. Here is an example of the usage of this trait:
Hopefully, this is quite straight forward since it just requires to insert 2 entries. The following example shoes how to insert terms with the slug `my_slug` and the title `My Terms`.

[source, php]
----
Expand All @@ -12,16 +12,36 @@ use RichId\TermsModuleBundle\Infrastructure\Migrations\TermsMigrationTrait;
final class RandomMigration extends AbstractMigration
{
use TermsMigrationTrait;
public function up(Schema $schema): void
{
$this->createTerms('my_slug', 'My Terms');
$this->addSQL("
INSERT INTO module_terms_terms
(slug, name, is_published, is_depublication_locked)
VALUES ('my_slug', 'My Terms', 0, 0)
");
$this->addSQL("
INSERT INTO module_terms_terms_version
(version, is_enabled, title, content, publication_date, terms_id)
VALUES (
1,
0,
'My title',
'My content',
CURRENT_TIME,
(SELECT id FROM module_terms_terms WHERE slug = 'my_slug')
)
");
}
public function down(Schema $schema): void
{
$this->deleteTerms('my_slug');
$this->addSQL("
DELETE FROM module_terms_terms_version AS version WHERE
version.terms_id = (SELECT terms.id FROM module_terms_terms WHERE terms.slug = 'my_slug')
");
$this->addSQL("DELETE FROM module_terms_terms WHERE slug = 'my_slug'");
}
}
----
5 changes: 5 additions & 0 deletions src/Infrastructure/Migrations/TermsMigrationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace RichId\TermsModuleBundle\Infrastructure\Migrations;

/**
* @deprecated The migrations should be stateless, please copy the raw SQL instead
*/
trait TermsMigrationTrait
{
/** @deprecated The migrations should be stateless, please copy the raw SQL instead */
protected function createTerms(
string $slug,
string $name,
Expand All @@ -31,6 +35,7 @@ protected function createTerms(
");
}

/** @deprecated The migrations should be stateless, please copy the raw SQL instead */
protected function deleteTerms(string $slug): void
{
$this->addSQL("
Expand Down

0 comments on commit a143b71

Please sign in to comment.