diff --git a/plugins/Tags/config/Migrations/20210831121348_TagSystem.php b/plugins/Tags/config/Migrations/20210831121348_TagSystem.php new file mode 100644 index 0000000..7b15623 --- /dev/null +++ b/plugins/Tags/config/Migrations/20210831121348_TagSystem.php @@ -0,0 +1,89 @@ +table('tags_tags') + ->addColumn('namespace', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]) + ->addColumn('predicate', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]) + ->addColumn('value', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]) + ->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]) + ->addColumn('colour', 'string', [ + 'default' => null, + 'limit' => 7, + 'null' => false, + ]) + ->addColumn('counter', 'integer', [ + 'default' => 0, + 'length' => 11, + 'null' => false, + 'signed' => false, + 'comment' => 'Field used by the CounterCache behaviour to count the occurence of tags' + ]) + ->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]) + ->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => false, + ]) + ->create(); + + $tagged = $this->table('tags_tagged') + ->addColumn('tag_id', 'integer', [ + 'default' => null, + 'null' => false, + 'signed' => false, + 'length' => 10, + ]) + ->addColumn('fk_id', 'integer', [ + 'default' => null, + 'null' => true, + 'signed' => false, + 'length' => 10, + 'comment' => 'The ID of the entity being tagged' + ]) + ->addColumn('fk_model', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + 'comment' => 'The model name of the entity being tagged' + ]) + ->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]) + ->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => false, + ]) + ->create(); + + $tags->addIndex(['name'], ['unique' => true]) + ->update(); + + $tagged->addIndex(['tag_id', 'fk_id', 'fk_table'], ['unique' => true]) + ->update(); + } +} \ No newline at end of file