mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-26 18:21:02 +00:00
Fix schema
This commit is contained in:
parent
750dd643d1
commit
b305d72740
14 changed files with 829 additions and 83 deletions
|
@ -41,6 +41,11 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA
|
|||
return false;
|
||||
}
|
||||
|
||||
protected function getTablePrefix(): string
|
||||
{
|
||||
return (string) $this->container->getParameter('database_table_prefix');
|
||||
}
|
||||
|
||||
protected function getTable($tableName, $unEscaped = false)
|
||||
{
|
||||
$table = $this->container->getParameter('database_table_prefix') . $tableName;
|
||||
|
@ -57,4 +62,35 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA
|
|||
// return escaped table
|
||||
return '`' . $table . '`';
|
||||
}
|
||||
|
||||
protected function getForeignKeyName(string $tableName, string $foreignColumnName): string
|
||||
{
|
||||
return $this->generateIdentifierName([$this->getTable($tableName, true), $foreignColumnName], 'fk');
|
||||
}
|
||||
|
||||
protected function getIndexName(string $tableName, $indexedColumnNames): string
|
||||
{
|
||||
$indexedColumnNames = (array) $indexedColumnNames;
|
||||
|
||||
return $this->generateIdentifierName(array_merge([$this->getTable($tableName, true)], $indexedColumnNames), 'idx');
|
||||
}
|
||||
|
||||
protected function getUniqueIndexName(string $tableName, string $indexedColumnName): string
|
||||
{
|
||||
return $this->generateIdentifierName([$this->getTable($tableName, true), $indexedColumnName], 'uniq');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Doctrine\DBAL\Schema\AbstractAsset::_generateIdentifierName
|
||||
*
|
||||
* @param string[] $columnNames
|
||||
*/
|
||||
protected function generateIdentifierName(array $columnNames, string $prefix = ''): string
|
||||
{
|
||||
$hash = implode('', array_map(static function ($column): string {
|
||||
return dechex(crc32($column));
|
||||
}, $columnNames));
|
||||
|
||||
return strtoupper(substr($prefix . '_' . $hash, 0, $this->platform->getMaxIdentifierLength()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,22 +8,6 @@ use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
|
|||
/**
|
||||
* @ORM\Table("oauth2_access_tokens")
|
||||
* @ORM\Entity
|
||||
* @ORM\AttributeOverrides({
|
||||
* @ORM\AttributeOverride(name="token",
|
||||
* column=@ORM\Column(
|
||||
* name = "token",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* ),
|
||||
* @ORM\AttributeOverride(name="scope",
|
||||
* column=@ORM\Column(
|
||||
* name = "scope",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* )
|
||||
* })
|
||||
*/
|
||||
class AccessToken extends BaseAccessToken
|
||||
{
|
||||
|
|
|
@ -8,22 +8,6 @@ use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
|
|||
/**
|
||||
* @ORM\Table("oauth2_auth_codes")
|
||||
* @ORM\Entity
|
||||
* @ORM\AttributeOverrides({
|
||||
* @ORM\AttributeOverride(name="token",
|
||||
* column=@ORM\Column(
|
||||
* name = "token",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* ),
|
||||
* @ORM\AttributeOverride(name="scope",
|
||||
* column=@ORM\Column(
|
||||
* name = "scope",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* )
|
||||
* })
|
||||
*/
|
||||
class AuthCode extends BaseAuthCode
|
||||
{
|
||||
|
|
|
@ -8,22 +8,6 @@ use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
|
|||
/**
|
||||
* @ORM\Table("oauth2_refresh_tokens")
|
||||
* @ORM\Entity
|
||||
* @ORM\AttributeOverrides({
|
||||
* @ORM\AttributeOverride(name="token",
|
||||
* column=@ORM\Column(
|
||||
* name = "token",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* ),
|
||||
* @ORM\AttributeOverride(name="scope",
|
||||
* column=@ORM\Column(
|
||||
* name = "scope",
|
||||
* type = "string",
|
||||
* length = 191
|
||||
* )
|
||||
* )
|
||||
* })
|
||||
*/
|
||||
class RefreshToken extends BaseRefreshToken
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* @ORM\Table(
|
||||
* name="`config`",
|
||||
* indexes={
|
||||
* @ORM\Index(name="config_feed_token", columns={"feed_token"}, options={"lengths"={255}}),
|
||||
* @ORM\Index(columns={"feed_token"}),
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
|
|
|
@ -21,16 +21,15 @@ use Wallabag\Helper\UrlHasher;
|
|||
* @ORM\Entity(repositoryClass="Wallabag\Repository\EntryRepository")
|
||||
* @ORM\Table(
|
||||
* name="`entry`",
|
||||
* options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
|
||||
* indexes={
|
||||
* @ORM\Index(name="created_at", columns={"created_at"}),
|
||||
* @ORM\Index(name="uid", columns={"uid"}),
|
||||
* @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}),
|
||||
* @ORM\Index(name="hashed_given_url_user_id", columns={"user_id", "hashed_given_url"}, options={"lengths"={null, 40}}),
|
||||
* @ORM\Index(name="user_language", columns={"language", "user_id"}),
|
||||
* @ORM\Index(name="user_archived", columns={"user_id", "is_archived", "archived_at"}),
|
||||
* @ORM\Index(name="user_created", columns={"user_id", "created_at"}),
|
||||
* @ORM\Index(name="user_starred", columns={"user_id", "is_starred", "starred_at"})
|
||||
* @ORM\Index(columns={"created_at"}),
|
||||
* @ORM\Index(columns={"uid"}),
|
||||
* @ORM\Index(columns={"user_id", "hashed_url"}),
|
||||
* @ORM\Index(columns={"user_id", "hashed_given_url"}),
|
||||
* @ORM\Index(columns={"language", "user_id"}),
|
||||
* @ORM\Index(columns={"user_id", "is_archived", "archived_at"}),
|
||||
* @ORM\Index(columns={"user_id", "created_at"}),
|
||||
* @ORM\Index(columns={"user_id", "is_starred", "starred_at"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
|
@ -279,7 +278,7 @@ class Entry
|
|||
*
|
||||
* @Exclude
|
||||
*
|
||||
* @ORM\Column(name="is_not_parsed", type="boolean")
|
||||
* @ORM\Column(name="is_not_parsed", type="boolean", options={"default": false})
|
||||
*
|
||||
* @Groups({"entries_for_user", "export_all"})
|
||||
*/
|
||||
|
@ -1017,11 +1016,9 @@ class Entry
|
|||
/**
|
||||
* Set isNotParsed.
|
||||
*
|
||||
* @param bool $isNotParsed
|
||||
*
|
||||
* @return Entry
|
||||
*/
|
||||
public function setNotParsed($isNotParsed)
|
||||
public function setNotParsed(bool $isNotParsed)
|
||||
{
|
||||
$this->isNotParsed = $isNotParsed;
|
||||
|
||||
|
@ -1030,10 +1027,8 @@ class Entry
|
|||
|
||||
/**
|
||||
* Get isNotParsed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotParsed()
|
||||
public function isNotParsed(): bool
|
||||
{
|
||||
return $this->isNotParsed;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface
|
|||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Wallabag\Entity\Config", inversedBy="ignoreOriginRules")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $config;
|
||||
|
||||
|
|
|
@ -12,25 +12,13 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*
|
||||
* @ORM\Entity(repositoryClass="Craue\ConfigBundle\Repository\SettingRepository")
|
||||
* @ORM\Table(name="`internal_setting`")
|
||||
* @ORM\AttributeOverrides({
|
||||
* @ORM\AttributeOverride(name="name",
|
||||
* column=@ORM\Column(
|
||||
* length = 191
|
||||
* )
|
||||
* ),
|
||||
* @ORM\AttributeOverride(name="section",
|
||||
* column=@ORM\Column(
|
||||
* length = 191
|
||||
* )
|
||||
* )
|
||||
* })
|
||||
*/
|
||||
class InternalSetting extends BaseSetting
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(name="value", type="string", nullable=true, length=191)
|
||||
* @ORM\Column(name="value", type="string", nullable=true)
|
||||
*/
|
||||
protected $value;
|
||||
}
|
||||
|
|
|
@ -59,14 +59,15 @@ class SiteCredential
|
|||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @var \DateTime|null
|
||||
*
|
||||
* @ORM\Column(name="updated_at", type="datetime")
|
||||
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
|
||||
*/
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Wallabag\Entity\User", inversedBy="siteCredentials")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $user;
|
||||
|
||||
|
@ -187,7 +188,7 @@ class SiteCredential
|
|||
/**
|
||||
* Get updatedAt.
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getUpdatedAt()
|
||||
{
|
||||
|
|
|
@ -15,9 +15,8 @@ use JMS\Serializer\Annotation\XmlRoot;
|
|||
* @XmlRoot("tag")
|
||||
* @ORM\Table(
|
||||
* name="`tag`",
|
||||
* options={"collate"="utf8mb4_bin", "charset"="utf8mb4"},
|
||||
* indexes={
|
||||
* @ORM\Index(name="tag_label", columns={"label"}, options={"lengths"={255}}),
|
||||
* @ORM\Index(columns={"label"}),
|
||||
* }
|
||||
* )
|
||||
* @ORM\Entity(repositoryClass="Wallabag\Repository\TagRepository")
|
||||
|
|
68
src/Event/Subscriber/SchemaAdapterSubscriber.php
Normal file
68
src/Event/Subscriber/SchemaAdapterSubscriber.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\Event\Subscriber;
|
||||
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
|
||||
|
||||
class SchemaAdapterSubscriber implements EventSubscriber
|
||||
{
|
||||
private string $databaseTablePrefix;
|
||||
|
||||
public function __construct(string $databaseTablePrefix)
|
||||
{
|
||||
$this->databaseTablePrefix = $databaseTablePrefix;
|
||||
}
|
||||
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return ['postGenerateSchema'];
|
||||
}
|
||||
|
||||
public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs)
|
||||
{
|
||||
$platform = $eventArgs->getEntityManager()->getConnection()->getDatabasePlatform();
|
||||
|
||||
if (!$platform instanceof MySQLPlatform) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = $eventArgs->getSchema();
|
||||
|
||||
$entryTable = $schema->getTable($this->databaseTablePrefix . 'entry');
|
||||
$entryTable->addOption('collate', 'utf8mb4_unicode_ci');
|
||||
$entryTable->addOption('charset', 'utf8mb4');
|
||||
|
||||
$tagTable = $schema->getTable($this->databaseTablePrefix . 'tag');
|
||||
$tagTable->addOption('collate', 'utf8mb4_bin');
|
||||
$tagTable->addOption('charset', 'utf8mb4');
|
||||
|
||||
foreach ($tagTable->getIndexes() as $index) {
|
||||
if ($index->getColumns() === ['label']) {
|
||||
$tagTable->dropIndex($index->getName());
|
||||
$tagTable->addIndex($index->getColumns(), $index->getName(), $index->getFlags(), array_merge(
|
||||
$index->getOptions(),
|
||||
['lengths' => [255]]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$oauth2AccessTokenTable = $schema->getTable($this->databaseTablePrefix . 'oauth2_access_tokens');
|
||||
$oauth2AccessTokenTable->modifyColumn('token', ['length' => 191]);
|
||||
$oauth2AccessTokenTable->modifyColumn('scope', ['length' => 191]);
|
||||
|
||||
$oauth2AuthCodeTable = $schema->getTable($this->databaseTablePrefix . 'oauth2_auth_codes');
|
||||
$oauth2AuthCodeTable->modifyColumn('token', ['length' => 191]);
|
||||
$oauth2AuthCodeTable->modifyColumn('scope', ['length' => 191]);
|
||||
|
||||
$oauth2RefreshTokenTable = $schema->getTable($this->databaseTablePrefix . 'oauth2_refresh_tokens');
|
||||
$oauth2RefreshTokenTable->modifyColumn('token', ['length' => 191]);
|
||||
$oauth2RefreshTokenTable->modifyColumn('scope', ['length' => 191]);
|
||||
|
||||
$internalSettingTable = $schema->getTable($this->databaseTablePrefix . 'internal_setting');
|
||||
$internalSettingTable->modifyColumn('name', ['length' => 191]);
|
||||
$internalSettingTable->modifyColumn('section', ['length' => 191]);
|
||||
$internalSettingTable->modifyColumn('value', ['length' => 191]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue