Skip to content

Commit

Permalink
fixed #196 by merging migrations to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
franzose committed Jul 24, 2017
1 parent a716df8 commit 05c9a2d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 143 deletions.
21 changes: 6 additions & 15 deletions src/Franzose/ClosureTable/Generators/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,22 @@ class Migration extends Generator
*/
public function create(array $options)
{
$paths = [];

$entityClass = $this->getClassName($options['entity-table']);
$closureClass = $this->getClassName($options['closure-table']);
$useInnoDB = $options['use-innodb'];
$stubPrefix = $useInnoDB ? '-innodb' : '';

$paths[] = $path = $this->getPath($options['entity-table'], $options['migrations-path']);
$stub = $this->getStub('entity' . $stubPrefix, 'migrations');
$path = $this->getPath($options['entity-table'], $options['migrations-path']);
$stub = $this->getPath('migration' . $stubPrefix, 'migrations');

$this->filesystem->put($path, $this->parseStub($stub, [
$this->filesystem->put($path, $this->parseStub($stub), [
'entity_table' => $options['entity-table'],
'entity_class' => $entityClass
]));

$paths[] = $path = $this->getPath($options['closure-table'], $options['migrations-path']);
$stub = $this->getStub('closuretable' . $stubPrefix, 'migrations');

$this->filesystem->put($path, $this->parseStub($stub, [
'entity_class' => $entityClass,
'closure_table' => $options['closure-table'],
'closure_class' => $closureClass,
'entity_table' => $options['entity-table']
]));
]);

return $paths;
return [$path];
}

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions src/Franzose/ClosureTable/Generators/stubs/migrations/entity.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class {{entity_class}}Migration extends Migration
{
public function up()
{
Schema::create('{{entity_table}}', function (Blueprint $table) {
$table->engine = 'InnoDB';

$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable();
$table->integer('position', false, true);
$table->integer('real_depth', false, true);
$table->softDeletes();

$table->foreign('parent_id')
->references('id')
->on('{{entity_table}}')
->onDelete('set null');
});

Schema::create('{{closure_table}}', function (Blueprint $table) {
$table->engine = 'InnoDB';

$table->increments('closure_id');
$table->integer('ancestor', false, true);
$table->integer('descendant', false, true);
$table->integer('depth', false, true);

$table->foreign('ancestor')
->references('id')
->on('{{entity_table}}')
->onDelete('cascade');

$table->foreign('descendant')
->references('id')
->on('{{entity_table}}')
->onDelete('cascade');
});
}

public function down()
{
Schema::table('{{closure_table}}', function (Blueprint $table) {
Schema::dropIfExists('{{closure_table}}');
});

Schema::table('{{entity_table}}', function (Blueprint $table) {
Schema::dropIfExists('{{entity_table}}');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class {{entity_class}}Migration extends Migration
{
public function up()
{
Schema::create('{{entity_table}}', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable();
$table->integer('position', false, true);
$table->integer('real_depth', false, true);
$table->softDeletes();

$table->foreign('parent_id')
->references('id')
->on('{{entity_table}}')
->onDelete('set null');
});

Schema::create('{{closure_table}}', function (Blueprint $table) {
$table->increments('closure_id');

$table->integer('ancestor', false, true);
$table->integer('descendant', false, true);
$table->integer('depth', false, true);

$table->foreign('ancestor')
->references('id')
->on('{{entity_table}}')
->onDelete('cascade');

$table->foreign('descendant')
->references('id')
->on('{{entity_table}}')
->onDelete('cascade');
});
}

public function down()
{
Schema::table('{{closure_table}}', function (Blueprint $table) {
Schema::dropIfExists('{{closure_table}}');
});

Schema::table('{{entity_table}}', function (Blueprint $table) {
Schema::dropIfExists('{{entity_table}}');
});
}
}

0 comments on commit 05c9a2d

Please sign in to comment.