diff --git a/data/migrations/Version20190930165521.php b/data/migrations/Version20190930165521.php new file mode 100644 index 00000000..2f4e277b --- /dev/null +++ b/data/migrations/Version20190930165521.php @@ -0,0 +1,55 @@ +getTable('short_urls'); + if ($shortUrls->hasColumn('domain_id')) { + return; + } + + $domains = $schema->createTable('domains'); + $domains->addColumn('id', Type::BIGINT, [ + 'unsigned' => true, + 'autoincrement' => true, + 'notnull' => true, + ]); + $domains->addColumn('authority', Type::STRING, [ + 'length' => 512, + 'notnull' => true, + ]); + $domains->addUniqueIndex(['authority']); + $domains->setPrimaryKey(['id']); + + $shortUrls->addColumn('domain_id', Type::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'); + } +}