2019_06_01_021536_change_wallet_uid_to_user_uid.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // Copyright 2019 Hackware SpA <human@hackware.cl>
  3. // This file is part of "Hackware Web Services Wallet" and licensed under
  4. // the terms of the GNU Affero General Public License version 3, or (at your
  5. // option) a later version. You should have received a copy of this license
  6. // along with the software. If not, see <https://www.gnu.org/licenses/>.
  7. use Illuminate\Support\Facades\Schema;
  8. use Illuminate\Database\Schema\Blueprint;
  9. use Illuminate\Database\Migrations\Migration;
  10. class ChangeWalletUidToUserUid extends Migration
  11. {
  12. /**
  13. * Run the migrations.
  14. *
  15. * @return void
  16. */
  17. public function up()
  18. {
  19. Schema::table('wallets', function (Blueprint $table) {
  20. $table->renameColumn('uid', 'user_uid');
  21. });
  22. // Looks like renaming a column gets executed after any other
  23. // operation, by separating functions I'm sure the column has
  24. // already been renamed.
  25. Schema::table('wallets', function (Blueprint $table) {
  26. $table->foreign('user_uid')
  27. ->references('uid')
  28. ->on('users')
  29. ->onUpdate('cascade')
  30. ->onDelete('restrict');
  31. });
  32. Schema::table('transactions', function (Blueprint $table) {
  33. $table->dropForeign(['wallet_uid']);
  34. $table->renameColumn('wallet_uid', 'user_uid');
  35. });
  36. Schema::table('transactions', function (Blueprint $table) {
  37. $table->foreign('user_uid')
  38. ->references('uid')
  39. ->on('users')
  40. ->onUpdate('cascade')
  41. ->onDelete('restrict');
  42. });
  43. }
  44. /**
  45. * Reverse the migrations.
  46. *
  47. * @return void
  48. */
  49. public function down()
  50. {
  51. Schema::table('wallets', function (Blueprint $table) {
  52. $table->dropForeign(['user_uid']);
  53. $table->renameColumn('user_uid', 'uid');
  54. });
  55. Schema::table('transactions', function (Blueprint $table) {
  56. $table->dropForeign(['user_uid']);
  57. $table->renameColumn('user_uid', 'wallet_uid');
  58. });
  59. Schema::table('transactions', function (Blueprint $table) {
  60. $table->foreign('wallet_uid')
  61. ->references('uid')
  62. ->on('wallets')
  63. ->onUpdate('cascade')
  64. ->onDelete('restrict');
  65. });
  66. }
  67. }