You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

  1. <?php
  2. use Movim\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. class AddAutoincrementToUrlsTable extends Migration
  5. {
  6. public function up()
  7. {
  8. $this->disableForeignKeyCheck();
  9. $this->schema->table('urls', function (Blueprint $table) {
  10. $table->dropPrimary();
  11. });
  12. $this->schema->table('urls', function (Blueprint $table) {
  13. $table->increments('id')->first();
  14. $table->unique('hash');
  15. });
  16. $this->schema->table('messages', function (Blueprint $table) {
  17. $table->integer('urlid')->unsigned()->nullable();
  18. $table->foreign('urlid')
  19. ->references('id')->on('urls')
  20. ->onDelete('set null');
  21. });
  22. $this->enableForeignKeyCheck();
  23. }
  24. public function down()
  25. {
  26. $this->disableForeignKeyCheck();
  27. $this->schema->table('messages', function (Blueprint $table) {
  28. $table->dropForeign('messages_urlid_foreign');
  29. $table->dropColumn('urlid');
  30. });
  31. $this->schema->table('urls', function (Blueprint $table) {
  32. $table->dropColumn('id');
  33. $table->dropUnique('urls_hash_unique');
  34. $table->primary('hash');
  35. });
  36. $this->enableForeignKeyCheck();
  37. }
  38. }