Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with transferring UUID and ULID as primary key #41

Merged
merged 15 commits into from
Dec 15, 2023
Prev Previous commit
Next Next commit
Fix
andrey-helldar committed Dec 15, 2023
commit 0acbdb0dc6af88854ee78aee0cf3d78e4a6b0eb1
1 change: 1 addition & 0 deletions tests/Concerns/Database.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
/** @mixin \Tests\Concerns\Connections */
trait Database
{
use HasUuidAndUlid;
use Seeders;

protected $connectors = [
23 changes: 23 additions & 0 deletions tests/Concerns/HasUuidAndUlid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Tests\Concerns;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Str;

trait HasUuidAndUlid
{
protected function hasUuid()
{
return method_exists(Blueprint::class, 'uuid')
&& method_exists(Str::class, 'uuid');
}

protected function hasUlid()
{
return method_exists(Blueprint::class, 'ulid')
&& method_exists(Str::class, 'ulid');
}
}
2 changes: 2 additions & 0 deletions tests/Concerns/Migration.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

abstract class Migration extends BaseMigration
{
use HasUuidAndUlid;

protected $table;

public function up()
5 changes: 2 additions & 3 deletions tests/Concerns/Seeders.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

namespace Tests\Concerns;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

@@ -14,11 +13,11 @@ protected function fillTables(): void
$this->fillTable($this->table_bar);
$this->fillTable($this->table_baz);

if (method_exists(Blueprint::class, 'ulid')) {
if ($this->hasUlid()) {
$this->fillUlidTable($this->table_ulid);
}

if (method_exists(Blueprint::class, 'uuid')) {
if ($this->hasUuid()) {
$this->fillUlidTable($this->table_uuid);
}
}
5 changes: 2 additions & 3 deletions tests/Unit/MysqlToMysqlTest.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
use DragonCode\MigrateDB\Constants\Drivers;
use DragonCode\MigrateDB\Exceptions\InvalidArgumentException;
use DragonCode\Support\Facades\Helpers\Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

@@ -233,7 +232,7 @@ public function testSame()

public function testUlidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'ulid')) {
if (! $this->hasUlid()) {
$this->assertTrue(true);

return;
@@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey()

public function testUuidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'uuid')) {
if (! $this->hasUuid()) {
$this->assertTrue(true);

return;
5 changes: 2 additions & 3 deletions tests/Unit/MysqlToPostgresTest.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
use DragonCode\MigrateDB\Constants\Drivers;
use DragonCode\MigrateDB\Exceptions\InvalidArgumentException;
use DragonCode\Support\Facades\Helpers\Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

@@ -233,7 +232,7 @@ public function testSame()

public function testUlidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'ulid')) {
if (! $this->hasUlid()) {
$this->assertTrue(true);

return;
@@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey()

public function testUuidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'uuid')) {
if (! $this->hasUuid()) {
$this->assertTrue(true);

return;
5 changes: 2 additions & 3 deletions tests/Unit/PostgresToMysqlTest.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
use DragonCode\MigrateDB\Constants\Drivers;
use DragonCode\MigrateDB\Exceptions\InvalidArgumentException;
use DragonCode\Support\Facades\Helpers\Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

@@ -233,7 +232,7 @@ public function testSame()

public function testUlidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'ulid')) {
if (! $this->hasUlid()) {
$this->assertTrue(true);

return;
@@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey()

public function testUuidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'uuid')) {
if (! $this->hasUuid()) {
$this->assertTrue(true);

return;
5 changes: 2 additions & 3 deletions tests/Unit/PostgresToPostgresTest.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
use DragonCode\MigrateDB\Constants\Drivers;
use DragonCode\MigrateDB\Exceptions\InvalidArgumentException;
use DragonCode\Support\Facades\Helpers\Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

@@ -233,7 +232,7 @@ public function testSame()

public function testUlidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'ulid')) {
if (! $this->hasUlid()) {
$this->assertTrue(true);

return;
@@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey()

public function testUuidKeysAsPrimaryKey()
{
if (! method_exists(Blueprint::class, 'uuid')) {
if (! $this->hasUuid()) {
$this->assertTrue(true);

return;
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class CreateUlidPrimaryKey extends Migration
public function up()
{
Schema::create($this->table, function (Blueprint $table) {
if (method_exists(Blueprint::class, 'ulid')) {
if ($this->hasUlid()) {
$table->ulid('ulid')->primary();
}

Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class CreateUuidPrimaryKey extends Migration
public function up()
{
Schema::create($this->table, function (Blueprint $table) {
if (method_exists(Blueprint::class, 'uuid')) {
if ($this->hasUuid()) {
$table->uuid('uuid')->primary();
}