Skip to content

Commit

Permalink
Fix migrations for MySQL 8
Browse files Browse the repository at this point in the history
  • Loading branch information
REBELinBLUE committed Oct 3, 2021
1 parent 6670a0f commit 081c982
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 7 additions & 4 deletions Makefile
Expand Up @@ -87,11 +87,11 @@ test: lint phpcs phpunit ##@shortcuts Runs most tests; but excludes integration

fulltest: lint phpcs phpunit integration ##@shortcuts Runs all tests

run: ##@docker Runs the containers
@docker-compose up -d --remove-orphans
run: deps ##@docker Runs the containers
@docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d --remove-orphans

dev: ##@docker Runs the containers with dev options
@docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans
dev: deps ##@docker Runs the containers with dev options
@docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.dev.yml up -d --remove-orphans

stop: ##@docker Stops the containers
@docker-compose down
Expand Down Expand Up @@ -121,6 +121,9 @@ reset: clean
-rm database/database.sqlite
-rm database/backups/*

deps:
test -f docker-compose.override.yml || echo 'version: "3"' > docker-compose.override.yml

## Generates helper files for IDEs
#ide:
# php artisan clear-compiled
Expand Down
Expand Up @@ -14,14 +14,13 @@ class FixTimestampDefaults extends Migration
*/
public function up()
{
$connection = config('database.default');
$driver = config('database.connections.' . $connection . '.driver');
$driver = DB::getDriverName();
if ($driver === 'mysql') {
DB::statement("SET SESSION sql_mode='ALLOW_INVALID_DATES'");

foreach ($this->tables as $table) {
DB::statement("ALTER TABLE {$table} MODIFY COLUMN created_at timestamp NULL DEFAULT NULL");
DB::statement("ALTER TABLE {$table} MODIFY COLUMN updated_at timestamp NULL DEFAULT NULL");
DB::statement("ALTER TABLE `{$table}` MODIFY COLUMN created_at timestamp NULL DEFAULT NULL");
DB::statement("ALTER TABLE `{$table}` MODIFY COLUMN updated_at timestamp NULL DEFAULT NULL");
}

DB::statement('ALTER TABLE failed_jobs MODIFY COLUMN failed_at timestamp NULL DEFAULT NULL');
Expand Down

0 comments on commit 081c982

Please sign in to comment.