Skip to content

Commit

Permalink
chore: cleanup and fix sqlite ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
luceos committed Nov 13, 2024
1 parent f7e6e56 commit 3b45d1e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\MariaDbConnection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

return [
'up' => function (Builder $schema) {
$preferences = $schema->getConnection()->getSchemaGrammar()->wrap('preferences');
$connection = $schema->getConnection();
$driver = $connection->getDriverName();

$preferences = $connection->getSchemaGrammar()->wrap('preferences');

if ($schema->getConnection()->getDriverName() === 'pgsql') {
$users = $schema->getConnection()->getSchemaGrammar()->wrapTable('users');
$schema->getConnection()->statement("ALTER TABLE $users ALTER COLUMN $preferences TYPE JSON USING $preferences::TEXT::JSON");
if ($driver === 'pgsql') {
$users = $connection->getSchemaGrammar()->wrapTable('users');
$connection->statement("ALTER TABLE $users ALTER COLUMN $preferences TYPE JSON USING $preferences::TEXT::JSON");
} else {
$schema->table('users', function (Blueprint $table) {
$table->json('preferences_json')->nullable();
});

if ($schema->getConnection()?->isMaria()) {
$schema->getConnection()->table('users')->update([
'preferences_json' => $schema->getConnection()->raw("IF(JSON_VALID(CONVERT($preferences USING utf8mb4)), CONVERT($preferences USING utf8mb4), NULL)"),
if ($connection instanceof MariaDbConnection) {
$connection->table('users')->update([
'preferences_json' => $connection->raw("IF(JSON_VALID(CONVERT($preferences USING utf8mb4)), CONVERT($preferences USING utf8mb4), NULL)"),
]);
} elseif ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('users')->update([
'preferences_json' => $schema->getConnection()->raw("CAST(CONVERT($preferences USING utf8mb4) AS JSON)"),
} elseif ($driver === 'mysql') {
$connection->table('users')->update([
'preferences_json' => $connection->raw("CAST(CONVERT($preferences USING utf8mb4) AS JSON)"),
]);
}

Expand All @@ -43,19 +47,22 @@
},

'down' => function (Builder $schema) {
$preferences = $schema->getConnection()->getSchemaGrammar()->wrap('preferences');
$connection = $schema->getConnection();
$driver = $connection->getDriverName();

$preferences = $connection->getSchemaGrammar()->wrap('preferences');

if ($schema->getConnection()->getDriverName() === 'pgsql') {
$users = $schema->getConnection()->getSchemaGrammar()->wrapTable('users');
$schema->getConnection()->statement("ALTER TABLE $users ALTER COLUMN $preferences TYPE BYTEA USING preferences::TEXT::BYTEA");
if ($driver === 'pgsql') {
$users = $connection->getSchemaGrammar()->wrapTable('users');
$connection->statement("ALTER TABLE $users ALTER COLUMN $preferences TYPE BYTEA USING preferences::TEXT::BYTEA");
} else {
$schema->table('users', function (Blueprint $table) {
$table->binary('preferences_binary')->nullable();
});

if ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('users')->update([
'preferences_binary' => $schema->getConnection()->raw($preferences),
if ($driver === 'mysql') {
$connection->table('users')->update([
'preferences_binary' => $connection->raw($preferences),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\MariaDbConnection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

return [
'up' => function (Builder $schema) {
if ($schema->getConnection()->getDriverName() === 'pgsql') {
$notifications = $schema->getConnection()->getSchemaGrammar()->wrapTable('notifications');
$data = $schema->getConnection()->getSchemaGrammar()->wrap('data');
$schema->getConnection()->statement("ALTER TABLE $notifications ALTER COLUMN $data TYPE JSON USING data::TEXT::JSON");
$connection = $schema->getConnection();
$driver = $connection->getDriverName();

if ($driver === 'pgsql') {
$notifications = $connection->getSchemaGrammar()->wrapTable('notifications');
$data = $connection->getSchemaGrammar()->wrap('data');
$connection->statement("ALTER TABLE $notifications ALTER COLUMN $data TYPE JSON USING data::TEXT::JSON");
} else {
$schema->table('notifications', function (Blueprint $table) {
$table->json('data_json')->nullable();
});

if ($schema->getConnection()?->isMaria()) {
$schema->getConnection()->table('notifications')->update([
'data_json' => $schema->getConnection()->raw('IF(JSON_VALID(CONVERT(data USING utf8mb4)), CONVERT(data USING utf8mb4), NULL)'),
if ($connection instanceof MariaDbConnection) {
$connection->table('notifications')->update([
'data_json' => $connection->raw("IF(JSON_VALID(CONVERT(data USING utf8mb4)), CONVERT(data USING utf8mb4), NULL)"),
]);
} elseif ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('notifications')->update([
'data_json' => $schema->getConnection()->raw('CAST(CONVERT(data USING utf8mb4) AS JSON)'),
} elseif ($driver === 'mysql') {
$connection->table('notifications')->update([
'data_json' => $connection->raw('CAST(CONVERT(data USING utf8mb4) AS JSON)'),
]);
}

Expand All @@ -42,18 +46,21 @@
},

'down' => function (Builder $schema) {
if ($schema->getConnection()->getDriverName() === 'pgsql') {
$notifications = $schema->getConnection()->getSchemaGrammar()->wrapTable('notifications');
$data = $schema->getConnection()->getSchemaGrammar()->wrap('data');
$schema->getConnection()->statement("ALTER TABLE $notifications ALTER COLUMN $data TYPE BYTEA USING data::TEXT::BYTEA");
$connection = $schema->getConnection();
$driver = $connection->getDriverName();

if ($driver === 'pgsql') {
$notifications = $connection->getSchemaGrammar()->wrapTable('notifications');
$data = $connection->getSchemaGrammar()->wrap('data');
$connection->statement("ALTER TABLE $notifications ALTER COLUMN $data TYPE BYTEA USING data::TEXT::BYTEA");
} else {
$schema->table('notifications', function (Blueprint $table) {
$table->binary('data_binary')->nullable();
});

if ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('notifications')->update([
'data_binary' => $schema->getConnection()->raw('data'),
if ($driver === 'mysql') {
$connection->table('notifications')->update([
'data_binary' => $connection->raw('data'),
]);
}

Expand Down

0 comments on commit 3b45d1e

Please sign in to comment.