diff --git a/module/Core/migrations/Version20160819142757.php b/module/Core/migrations/Version20160819142757.php deleted file mode 100644 index 171c5b7e..00000000 --- a/module/Core/migrations/Version20160819142757.php +++ /dev/null @@ -1,49 +0,0 @@ -connection->getDatabasePlatform(); - $table = $schema->getTable('short_urls'); - $column = $table->getColumn('short_code'); - - match (true) { - is_subclass_of($platformClass, MySQLPlatform::class) => $column - ->setPlatformOption('charset', 'utf8mb4') - ->setPlatformOption('collation', 'utf8mb4_bin'), - is_subclass_of($platformClass, SQLitePlatform::class) => $column->setPlatformOption('collate', 'BINARY'), - default => null, - }; - } - - public function down(Schema $schema): void - { - // Nothing to roll back - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20160820191203.php b/module/Core/migrations/Version20160820191203.php deleted file mode 100644 index dea327b1..00000000 --- a/module/Core/migrations/Version20160820191203.php +++ /dev/null @@ -1,82 +0,0 @@ -getTables(); - foreach ($tables as $table) { - if ($table->getName() === 'tags') { - return; - } - } - - $this->createTagsTable($schema); - $this->createShortUrlsInTagsTable($schema); - } - - private function createTagsTable(Schema $schema): void - { - $table = $schema->createTable('tags'); - $table->addColumn('id', Types::BIGINT, [ - 'unsigned' => true, - 'autoincrement' => true, - 'notnull' => true, - ]); - $table->addColumn('name', Types::STRING, [ - 'length' => 255, - 'notnull' => true, - ]); - $table->addUniqueIndex(['name']); - - $table->setPrimaryKey(['id']); - } - - private function createShortUrlsInTagsTable(Schema $schema): void - { - $table = $schema->createTable('short_urls_in_tags'); - $table->addColumn('short_url_id', Types::BIGINT, [ - 'unsigned' => true, - 'notnull' => true, - ]); - $table->addColumn('tag_id', Types::BIGINT, [ - 'unsigned' => true, - 'notnull' => true, - ]); - - $table->addForeignKeyConstraint('tags', ['tag_id'], ['id'], [ - 'onDelete' => 'CASCADE', - 'onUpdate' => 'RESTRICT', - ]); - $table->addForeignKeyConstraint('short_urls', ['short_url_id'], ['id'], [ - 'onDelete' => 'CASCADE', - 'onUpdate' => 'RESTRICT', - ]); - - $table->setPrimaryKey(['short_url_id', 'tag_id']); - } - - public function down(Schema $schema): void - { - $schema->dropTable('short_urls_in_tags'); - $schema->dropTable('tags'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20171021093246.php b/module/Core/migrations/Version20171021093246.php deleted file mode 100644 index a810f49c..00000000 --- a/module/Core/migrations/Version20171021093246.php +++ /dev/null @@ -1,54 +0,0 @@ -getTable('short_urls'); - if ($shortUrls->hasColumn('valid_since')) { - return; - } - - $shortUrls->addColumn('valid_since', Types::DATETIME_MUTABLE, [ - 'notnull' => false, - ]); - $shortUrls->addColumn('valid_until', Types::DATETIME_MUTABLE, [ - 'notnull' => false, - ]); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - if (! $shortUrls->hasColumn('valid_since')) { - return; - } - - $shortUrls->dropColumn('valid_since'); - $shortUrls->dropColumn('valid_until'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20171022064541.php b/module/Core/migrations/Version20171022064541.php deleted file mode 100644 index fb5f8d7a..00000000 --- a/module/Core/migrations/Version20171022064541.php +++ /dev/null @@ -1,51 +0,0 @@ -getTable('short_urls'); - if ($shortUrls->hasColumn('max_visits')) { - return; - } - - $shortUrls->addColumn('max_visits', Types::INTEGER, [ - 'unsigned' => true, - 'notnull' => false, - ]); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - if (! $shortUrls->hasColumn('max_visits')) { - return; - } - - $shortUrls->dropColumn('max_visits'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20180801183328.php b/module/Core/migrations/Version20180801183328.php deleted file mode 100644 index 5fd40030..00000000 --- a/module/Core/migrations/Version20180801183328.php +++ /dev/null @@ -1,48 +0,0 @@ -setSize($schema, self::NEW_SIZE); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $this->setSize($schema, self::OLD_SIZE); - } - - /** - * @throws SchemaException - */ - private function setSize(Schema $schema, int $size): void - { - $schema->getTable('short_urls')->getColumn('short_code')->setLength($size); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20180913205455.php b/module/Core/migrations/Version20180913205455.php deleted file mode 100644 index de709bc8..00000000 --- a/module/Core/migrations/Version20180913205455.php +++ /dev/null @@ -1,74 +0,0 @@ -connection->createQueryBuilder(); - $qb->select('id', 'remote_addr') - ->from('visits'); - $st = $this->connection->executeQuery($qb->getSQL()); - - $qb = $this->connection->createQueryBuilder(); - $qb->update('visits') - ->set('remote_addr', ':obfuscatedAddr') - ->where('id=:id'); - - while ($row = $st->fetchAssociative()) { - $addr = $row['remote_addr'] ?? null; - if ($addr === null) { - continue; - } - - $qb->setParameters([ - 'id' => $row['id'], - 'obfuscatedAddr' => $this->determineAddress((string) $addr), - ])->executeQuery(); - } - } - - private function determineAddress(string $addr): ?string - { - if ($addr === IpAddress::LOCALHOST) { - return $addr; - } - - try { - return (string) IpAddress::fromString($addr)->getAnonymizedCopy(); - } catch (InvalidArgumentException) { - return null; - } - } - - public function down(Schema $schema): void - { - // Nothing to rollback - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20180915110857.php b/module/Core/migrations/Version20180915110857.php deleted file mode 100644 index b31ac105..00000000 --- a/module/Core/migrations/Version20180915110857.php +++ /dev/null @@ -1,56 +0,0 @@ - 'SET NULL', - 'short_urls' => 'CASCADE', - ]; - - /** - * @throws SchemaException - */ - public function up(Schema $schema): void - { - $visits = $schema->getTable('visits'); - $foreignKeys = $visits->getForeignKeys(); - - // Remove all existing foreign keys and add them again with CASCADE delete - foreach ($foreignKeys as $foreignKey) { - $visits->removeForeignKey($foreignKey->getName()); - $foreignTable = $foreignKey->getForeignTableName(); - - $visits->addForeignKeyConstraint( - $foreignTable, - $foreignKey->getLocalColumns(), - $foreignKey->getForeignColumns(), - [ - 'onDelete' => self::ON_DELETE_MAP[$foreignTable], - 'onUpdate' => 'RESTRICT', - ], - ); - } - } - - public function down(Schema $schema): void - { - // Nothing to run - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20181020060559.php b/module/Core/migrations/Version20181020060559.php deleted file mode 100644 index 908bf304..00000000 --- a/module/Core/migrations/Version20181020060559.php +++ /dev/null @@ -1,74 +0,0 @@ - 'country_code', - 'countryName' => 'country_name', - 'regionName' => 'region_name', - 'cityName' => 'city_name', - ]; - - /** - * @throws SchemaException - */ - public function up(Schema $schema): void - { - $this->createColumns($schema->getTable('visit_locations'), self::COLUMNS); - } - - private function createColumns(Table $visitLocations, array $columnNames): void - { - foreach ($columnNames as $name) { - if (! $visitLocations->hasColumn($name)) { - $visitLocations->addColumn($name, Types::STRING, ['notnull' => false]); - } - } - } - - /** - * @throws SchemaException - * @throws Exception - */ - public function postUp(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - - // If the camel case columns do not exist, do nothing - if (! $visitLocations->hasColumn('countryCode')) { - return; - } - - $qb = $this->connection->createQueryBuilder(); - $qb->update('visit_locations'); - foreach (self::COLUMNS as $camelCaseName => $snakeCaseName) { - $qb->set($snakeCaseName, $camelCaseName); - } - $qb->executeStatement(); - } - - public function down(Schema $schema): void - { - // No down - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20181020065148.php b/module/Core/migrations/Version20181020065148.php deleted file mode 100644 index 873e7f11..00000000 --- a/module/Core/migrations/Version20181020065148.php +++ /dev/null @@ -1,47 +0,0 @@ -getTable('visit_locations'); - - foreach (self::CAMEL_CASE_COLUMNS as $name) { - if ($visitLocations->hasColumn($name)) { - $visitLocations->dropColumn($name); - } - } - } - - public function down(Schema $schema): void - { - // No down - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20181110175521.php b/module/Core/migrations/Version20181110175521.php deleted file mode 100644 index 9fb989fa..00000000 --- a/module/Core/migrations/Version20181110175521.php +++ /dev/null @@ -1,43 +0,0 @@ -getUserAgentColumn($schema)->setLength(512); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $this->getUserAgentColumn($schema)->setLength(256); - } - - /** - * @throws SchemaException - */ - private function getUserAgentColumn(Schema $schema): Column - { - return $schema->getTable('visits')->getColumn('user_agent'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20190824075137.php b/module/Core/migrations/Version20190824075137.php deleted file mode 100644 index 663111ff..00000000 --- a/module/Core/migrations/Version20190824075137.php +++ /dev/null @@ -1,43 +0,0 @@ -getRefererColumn($schema)->setLength(1024); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $this->getRefererColumn($schema)->setLength(256); - } - - /** - * @throws SchemaException - */ - private function getRefererColumn(Schema $schema): Column - { - return $schema->getTable('visits')->getColumn('referer'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20190930165521.php b/module/Core/migrations/Version20190930165521.php deleted file mode 100644 index 97863843..00000000 --- a/module/Core/migrations/Version20190930165521.php +++ /dev/null @@ -1,61 +0,0 @@ -getTable('short_urls'); - if ($shortUrls->hasColumn('domain_id')) { - return; - } - - $domains = $schema->createTable('domains'); - $domains->addColumn('id', Types::BIGINT, [ - 'unsigned' => true, - 'autoincrement' => true, - 'notnull' => true, - ]); - $domains->addColumn('authority', Types::STRING, [ - 'length' => 512, - 'notnull' => true, - ]); - $domains->addUniqueIndex(['authority']); - $domains->setPrimaryKey(['id']); - - $shortUrls->addColumn('domain_id', Types::BIGINT, [ - 'unsigned' => true, - 'notnull' => false, - ]); - $shortUrls->addForeignKeyConstraint('domains', ['domain_id'], ['id'], [ - 'onDelete' => 'RESTRICT', - 'onUpdate' => 'RESTRICT', - ]); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $schema->getTable('short_urls')->dropColumn('domain_id'); - $schema->dropTable('domains'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20191001201532.php b/module/Core/migrations/Version20191001201532.php deleted file mode 100644 index fa13b85d..00000000 --- a/module/Core/migrations/Version20191001201532.php +++ /dev/null @@ -1,55 +0,0 @@ -getTable('short_urls'); - if ($shortUrls->hasIndex('unique_short_code_plus_domain')) { - return; - } - - /** @var Index|null $shortCodesIndex */ - $shortCodesIndex = array_reduce($shortUrls->getIndexes(), function (?Index $found, Index $current) { - [$column] = $current->getColumns(); - return $column === 'short_code' ? $current : $found; - }); - if ($shortCodesIndex === null) { - return; - } - - $shortUrls->dropIndex($shortCodesIndex->getName()); - $shortUrls->addUniqueIndex(['short_code', 'domain_id'], 'unique_short_code_plus_domain'); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - - $shortUrls->dropIndex('unique_short_code_plus_domain'); - $shortUrls->addUniqueIndex(['short_code']); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20191020074522.php b/module/Core/migrations/Version20191020074522.php deleted file mode 100644 index c1b9aea9..00000000 --- a/module/Core/migrations/Version20191020074522.php +++ /dev/null @@ -1,43 +0,0 @@ -getOriginalUrlColumn($schema)->setLength(2048); - } - - /** - * @throws SchemaException - */ - public function down(Schema $schema): void - { - $this->getOriginalUrlColumn($schema)->setLength(1024); - } - - /** - * @throws SchemaException - */ - private function getOriginalUrlColumn(Schema $schema): Column - { - return $schema->getTable('short_urls')->getColumn('original_url'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20200105165647.php b/module/Core/migrations/Version20200105165647.php deleted file mode 100644 index 1af26797..00000000 --- a/module/Core/migrations/Version20200105165647.php +++ /dev/null @@ -1,103 +0,0 @@ - 'latitude', 'lon' => 'longitude']; - - /** - * @throws Exception - */ - public function preUp(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - $this->skipIf(some( - self::COLUMNS, - fn (string $v, string|int $newColName) => $visitLocations->hasColumn((string) $newColName), - ), 'New columns already exist'); - - foreach (self::COLUMNS as $columnName) { - $qb = $this->connection->createQueryBuilder(); - $qb->update('visit_locations') - ->set($columnName, ':zeroValue') - ->where($qb->expr()->or( - $qb->expr()->eq($columnName, ':emptyString'), - $qb->expr()->isNull($columnName), - )) - ->setParameters([ - 'zeroValue' => '0', - 'emptyString' => '', - ]) - ->executeStatement(); - } - } - - /** - * @throws Exception - */ - public function up(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - - foreach (self::COLUMNS as $newName => $oldName) { - $visitLocations->addColumn($newName, Types::FLOAT, [ - 'default' => '0.0', - ]); - } - } - - /** - * @throws Exception - */ - public function postUp(Schema $schema): void - { - $isPostgres = $this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform; - $castType = $isPostgres ? 'DOUBLE PRECISION' : 'DECIMAL(9,2)'; - - foreach (self::COLUMNS as $newName => $oldName) { - $qb = $this->connection->createQueryBuilder(); - $qb->update('visit_locations') - ->set($newName, 'CAST(' . $oldName . ' AS ' . $castType . ')') - ->executeStatement(); - } - } - - public function preDown(Schema $schema): void - { - foreach (self::COLUMNS as $newName => $oldName) { - $qb = $this->connection->createQueryBuilder(); - $qb->update('visit_locations') - ->set($oldName, $newName) - ->executeStatement(); - } - } - - /** - * @throws Exception - */ - public function down(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - - foreach (self::COLUMNS as $colName => $oldName) { - $visitLocations->dropColumn($colName); - } - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20200106215144.php b/module/Core/migrations/Version20200106215144.php deleted file mode 100644 index f5faba4e..00000000 --- a/module/Core/migrations/Version20200106215144.php +++ /dev/null @@ -1,60 +0,0 @@ -getTable('visit_locations'); - $this->skipIf($this->oldColumnsDoNotExist($visitLocations), 'Old columns do not exist'); - - foreach (self::COLUMNS as $colName) { - $visitLocations->dropColumn($colName); - } - } - - public function oldColumnsDoNotExist(Table $visitLocations): bool - { - foreach (self::COLUMNS as $oldColName) { - if ($visitLocations->hasColumn($oldColName)) { - return false; - } - } - - return true; - } - - /** - * @throws Exception - */ - public function down(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - - foreach (self::COLUMNS as $colName) { - $visitLocations->addColumn($colName, Types::STRING, [ - 'notnull' => false, - ]); - } - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20200110182849.php b/module/Core/migrations/Version20200110182849.php deleted file mode 100644 index 4b608bb2..00000000 --- a/module/Core/migrations/Version20200110182849.php +++ /dev/null @@ -1,60 +0,0 @@ - [ - 'referer', - 'user_agent', - ], - 'visit_locations' => [ - 'timezone', - 'country_code', - 'country_name', - 'region_name', - 'city_name', - ], - ]; - - public function up(Schema $schema): void - { - foreach (self::COLUMN_DEFAULTS_MAP as $tableName => $columns) { - foreach ($columns as $columnName) { - $this->setDefaultValueForColumnInTable($tableName, $columnName); - } - } - } - - /** - * @throws Exception - */ - public function setDefaultValueForColumnInTable(string $tableName, string $columnName): void - { - $qb = $this->connection->createQueryBuilder(); - $qb->update($tableName) - ->set($columnName, ':emptyValue') - ->setParameter('emptyValue', self::DEFAULT_EMPTY_VALUE) - ->where($qb->expr()->isNull($columnName)) - ->executeStatement(); - } - - public function down(Schema $schema): void - { - // No need (and no way) to undo this migration - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20200323190014.php b/module/Core/migrations/Version20200323190014.php deleted file mode 100644 index b47fc65c..00000000 --- a/module/Core/migrations/Version20200323190014.php +++ /dev/null @@ -1,52 +0,0 @@ -getTable('visit_locations'); - $this->skipIf($visitLocations->hasColumn('is_empty')); - - $visitLocations->addColumn('is_empty', Types::BOOLEAN, ['default' => false]); - } - - public function postUp(Schema $schema): void - { - $qb = $this->connection->createQueryBuilder(); - $qb->update('visit_locations') - ->set('is_empty', ':isEmpty') - ->where($qb->expr()->eq('country_code', ':emptyString')) - ->andWhere($qb->expr()->eq('country_name', ':emptyString')) - ->andWhere($qb->expr()->eq('region_name', ':emptyString')) - ->andWhere($qb->expr()->eq('city_name', ':emptyString')) - ->andWhere($qb->expr()->eq('timezone', ':emptyString')) - ->andWhere($qb->expr()->eq('lat', ':latLong')) - ->andWhere($qb->expr()->eq('lon', ':latLong')) - ->setParameter('isEmpty', true) - ->setParameter('emptyString', '') - ->setParameter('latLong', 0) - ->executeStatement(); - } - - public function down(Schema $schema): void - { - $visitLocations = $schema->getTable('visit_locations'); - $this->skipIf(!$visitLocations->hasColumn('is_empty')); - - $visitLocations->dropColumn('is_empty'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20200503170404.php b/module/Core/migrations/Version20200503170404.php deleted file mode 100644 index ad2c63df..00000000 --- a/module/Core/migrations/Version20200503170404.php +++ /dev/null @@ -1,33 +0,0 @@ -getTable('visits'); - $this->skipIf($visits->hasIndex(self::INDEX_NAME)); - $visits->addIndex(['date'], self::INDEX_NAME); - } - - public function down(Schema $schema): void - { - $visits = $schema->getTable('visits'); - $this->skipIf(! $visits->hasIndex(self::INDEX_NAME)); - $visits->dropIndex(self::INDEX_NAME); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20201023090929.php b/module/Core/migrations/Version20201023090929.php deleted file mode 100644 index 4655cbd5..00000000 --- a/module/Core/migrations/Version20201023090929.php +++ /dev/null @@ -1,50 +0,0 @@ -getTable('short_urls'); - $this->skipIf($shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN)); - - $shortUrls->addColumn(self::IMPORT_SOURCE_COLUMN, Types::STRING, [ - 'length' => 255, - 'notnull' => false, - ]); - $shortUrls->addColumn('import_original_short_code', Types::STRING, [ - 'length' => 255, - 'notnull' => false, - ]); - - $shortUrls->addUniqueIndex( - [self::IMPORT_SOURCE_COLUMN, 'import_original_short_code', 'domain_id'], - 'unique_imports', - ); - } - - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - $this->skipIf(! $shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN)); - - $shortUrls->dropColumn(self::IMPORT_SOURCE_COLUMN); - $shortUrls->dropColumn('import_original_short_code'); - $shortUrls->dropIndex('unique_imports'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20201102113208.php b/module/Core/migrations/Version20201102113208.php deleted file mode 100644 index 4bae99e1..00000000 --- a/module/Core/migrations/Version20201102113208.php +++ /dev/null @@ -1,91 +0,0 @@ -getTable('short_urls'); - $this->skipIf($shortUrls->hasColumn(self::API_KEY_COLUMN)); - - $shortUrls->addColumn(self::API_KEY_COLUMN, Types::BIGINT, [ - 'unsigned' => true, - 'notnull' => false, - ]); - - $shortUrls->addForeignKeyConstraint('api_keys', [self::API_KEY_COLUMN], ['id'], [ - 'onDelete' => 'SET NULL', - 'onUpdate' => 'RESTRICT', - ], 'FK_' . self::API_KEY_COLUMN); - } - - public function postUp(Schema $schema): void - { - // If there's only one API key, and it's active, link all existing URLs with it - $qb = $this->connection->createQueryBuilder(); - $qb->select('id') - ->from('api_keys') - ->where($qb->expr()->eq('enabled', ':enabled')) - ->andWhere($qb->expr()->or( - $qb->expr()->isNull('expiration_date'), - $qb->expr()->gt('expiration_date', ':expiration'), - )) - ->setParameters([ - 'enabled' => true, - 'expiration' => Chronos::now()->toDateTimeString(), - ]); - - $result = $qb->executeQuery(); - $id = $this->resolveOneApiKeyId($result); - if ($id === null) { - return; - } - - $qb = $this->connection->createQueryBuilder(); - $qb->update('short_urls') - ->set(self::API_KEY_COLUMN, ':apiKeyId') - ->setParameter('apiKeyId', $id) - ->executeQuery(); - } - - private function resolveOneApiKeyId(Result $result): string|int|null - { - $results = []; - while ($row = $result->fetchAssociative()) { - // As soon as we have to iterate more than once, then we cannot resolve a single API key - if (! empty($results)) { - return null; - } - - $results[] = $row['id'] ?? null; - } - - return $results[0] ?? null; - } - - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - $this->skipIf(! $shortUrls->hasColumn(self::API_KEY_COLUMN)); - - $shortUrls->removeForeignKey('FK_' . self::API_KEY_COLUMN); - $shortUrls->dropColumn(self::API_KEY_COLUMN); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210102174433.php b/module/Core/migrations/Version20210102174433.php deleted file mode 100644 index 58ea36cd..00000000 --- a/module/Core/migrations/Version20210102174433.php +++ /dev/null @@ -1,58 +0,0 @@ -skipIf($schema->hasTable(self::TABLE_NAME)); - - $table = $schema->createTable(self::TABLE_NAME); - $table->addColumn('id', Types::BIGINT, [ - 'unsigned' => true, - 'autoincrement' => true, - 'notnull' => true, - ]); - $table->setPrimaryKey(['id']); - - $table->addColumn('role_name', Types::STRING, [ - 'length' => 255, - 'notnull' => true, - ]); - $table->addColumn('meta', Types::JSON, [ - 'notnull' => true, - ]); - - $table->addColumn('api_key_id', Types::BIGINT, [ - 'unsigned' => true, - 'notnull' => true, - ]); - $table->addForeignKeyConstraint('api_keys', ['api_key_id'], ['id'], [ - 'onDelete' => 'CASCADE', - 'onUpdate' => 'RESTRICT', - ]); - $table->addUniqueIndex(['role_name', 'api_key_id'], 'UQ_role_plus_api_key'); - } - - public function down(Schema $schema): void - { - $this->skipIf(! $schema->hasTable(self::TABLE_NAME)); - $schema->getTable(self::TABLE_NAME)->dropIndex('UQ_role_plus_api_key'); - $schema->dropTable(self::TABLE_NAME); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210118153932.php b/module/Core/migrations/Version20210118153932.php deleted file mode 100644 index 476f8d84..00000000 --- a/module/Core/migrations/Version20210118153932.php +++ /dev/null @@ -1,32 +0,0 @@ -getTable('api_key_roles'); - $nameColumn = $rolesTable->getColumn('role_name'); - $nameColumn->setLength(255); - } - - public function down(Schema $schema): void - { - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210202181026.php b/module/Core/migrations/Version20210202181026.php deleted file mode 100644 index 7a63b814..00000000 --- a/module/Core/migrations/Version20210202181026.php +++ /dev/null @@ -1,42 +0,0 @@ -getTable('short_urls'); - $this->skipIf($shortUrls->hasColumn(self::TITLE)); - - $shortUrls->addColumn(self::TITLE, Types::STRING, [ - 'notnull' => false, - 'length' => 512, - ]); - $shortUrls->addColumn('title_was_auto_resolved', Types::BOOLEAN, [ - 'default' => false, - ]); - } - - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - $this->skipIf(! $shortUrls->hasColumn(self::TITLE)); - $shortUrls->dropColumn(self::TITLE); - $shortUrls->dropColumn('title_was_auto_resolved'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210207100807.php b/module/Core/migrations/Version20210207100807.php deleted file mode 100644 index 4a77eba2..00000000 --- a/module/Core/migrations/Version20210207100807.php +++ /dev/null @@ -1,49 +0,0 @@ -getTable('visits'); - $this->skipIf($visits->hasColumn('visited_url')); - - $shortUrlId = $visits->getColumn('short_url_id'); - $shortUrlId->setNotnull(false); - - $visits->addColumn('visited_url', Types::STRING, [ - 'length' => Visitor::VISITED_URL_MAX_LENGTH, - 'notnull' => false, - ]); - $visits->addColumn('type', Types::STRING, [ - 'length' => 255, - 'default' => VisitType::VALID_SHORT_URL->value, - ]); - } - - public function down(Schema $schema): void - { - $visits = $schema->getTable('visits'); - $this->skipIf(! $visits->hasColumn('visited_url')); - - $shortUrlId = $visits->getColumn('short_url_id'); - $shortUrlId->setNotnull(true); - $visits->dropColumn('visited_url'); - $visits->dropColumn('type'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210306165711.php b/module/Core/migrations/Version20210306165711.php deleted file mode 100644 index ba1a4476..00000000 --- a/module/Core/migrations/Version20210306165711.php +++ /dev/null @@ -1,43 +0,0 @@ -getTable(self::TABLE); - $this->skipIf($apiKeys->hasColumn(self::COLUMN)); - - $apiKeys->addColumn( - self::COLUMN, - Types::STRING, - [ - 'notnull' => false, - ], - ); - } - - public function down(Schema $schema): void - { - $apiKeys = $schema->getTable(self::TABLE); - $this->skipIf(! $apiKeys->hasColumn(self::COLUMN)); - - $apiKeys->dropColumn(self::COLUMN); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210522051601.php b/module/Core/migrations/Version20210522051601.php deleted file mode 100644 index 279c7a7e..00000000 --- a/module/Core/migrations/Version20210522051601.php +++ /dev/null @@ -1,32 +0,0 @@ -getTable('short_urls'); - $this->skipIf($shortUrls->hasColumn('crawlable')); - $shortUrls->addColumn('crawlable', Types::BOOLEAN, ['default' => false]); - } - - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - $this->skipIf(! $shortUrls->hasColumn('crawlable')); - $shortUrls->dropColumn('crawlable'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210522124633.php b/module/Core/migrations/Version20210522124633.php deleted file mode 100644 index 921e0831..00000000 --- a/module/Core/migrations/Version20210522124633.php +++ /dev/null @@ -1,34 +0,0 @@ -getTable('visits'); - $this->skipIf($visits->hasColumn(self::POTENTIAL_BOT_COLUMN)); - $visits->addColumn(self::POTENTIAL_BOT_COLUMN, Types::BOOLEAN, ['default' => false]); - } - - public function down(Schema $schema): void - { - $visits = $schema->getTable('visits'); - $this->skipIf(! $visits->hasColumn(self::POTENTIAL_BOT_COLUMN)); - $visits->dropColumn(self::POTENTIAL_BOT_COLUMN); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20210720143824.php b/module/Core/migrations/Version20210720143824.php deleted file mode 100644 index 407c5c79..00000000 --- a/module/Core/migrations/Version20210720143824.php +++ /dev/null @@ -1,47 +0,0 @@ -getTable('domains'); - $this->skipIf($domainsTable->hasColumn('base_url_redirect')); - - $this->createRedirectColumn($domainsTable, 'base_url_redirect'); - $this->createRedirectColumn($domainsTable, 'regular_not_found_redirect'); - $this->createRedirectColumn($domainsTable, 'invalid_short_url_redirect'); - } - - private function createRedirectColumn(Table $table, string $columnName): void - { - $table->addColumn($columnName, Types::STRING, [ - 'notnull' => false, - 'default' => null, - ]); - } - - public function down(Schema $schema): void - { - $domainsTable = $schema->getTable('domains'); - $this->skipIf(! $domainsTable->hasColumn('base_url_redirect')); - - $domainsTable->dropColumn('base_url_redirect'); - $domainsTable->dropColumn('regular_not_found_redirect'); - $domainsTable->dropColumn('invalid_short_url_redirect'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20211002072605.php b/module/Core/migrations/Version20211002072605.php deleted file mode 100644 index 970d51d6..00000000 --- a/module/Core/migrations/Version20211002072605.php +++ /dev/null @@ -1,32 +0,0 @@ -getTable('short_urls'); - $this->skipIf($shortUrls->hasColumn('forward_query')); - $shortUrls->addColumn('forward_query', Types::BOOLEAN, ['default' => true]); - } - - public function down(Schema $schema): void - { - $shortUrls = $schema->getTable('short_urls'); - $this->skipIf(! $shortUrls->hasColumn('forward_query')); - $shortUrls->dropColumn('forward_query'); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -}