diff --git a/src/Franzose/ClosureTable/Generators/Migration.php b/src/Franzose/ClosureTable/Generators/Migration.php index 183dca0..8d7937b 100644 --- a/src/Franzose/ClosureTable/Generators/Migration.php +++ b/src/Franzose/ClosureTable/Generators/Migration.php @@ -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]; } /** diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable-innodb.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable-innodb.php deleted file mode 100644 index dadb63f..0000000 --- a/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable-innodb.php +++ /dev/null @@ -1,35 +0,0 @@ -engine = 'InnoDB'; - - 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}}'); - }); - } -} diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable.php deleted file mode 100644 index ee08a53..0000000 --- a/src/Franzose/ClosureTable/Generators/stubs/migrations/closuretable.php +++ /dev/null @@ -1,30 +0,0 @@ -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}}'); - }); - } -} diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/entity-innodb.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/entity-innodb.php deleted file mode 100644 index e7cc714..0000000 --- a/src/Franzose/ClosureTable/Generators/stubs/migrations/entity-innodb.php +++ /dev/null @@ -1,34 +0,0 @@ -engine = 'InnoDB'; - - 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'); - }); - }); - } - - public function down() - { - Schema::table('{{entity_table}}', function(Blueprint $table) - { - Schema::dropIfExists('{{entity_table}}'); - }); - } -} diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/entity.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/entity.php deleted file mode 100644 index cf23f4a..0000000 --- a/src/Franzose/ClosureTable/Generators/stubs/migrations/entity.php +++ /dev/null @@ -1,29 +0,0 @@ -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'); - }); - } - - public function down() - { - Schema::table('{{entity_table}}', function(Blueprint $table) - { - Schema::dropIfExists('{{entity_table}}'); - }); - } -} diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/migration-innodb.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/migration-innodb.php new file mode 100644 index 0000000..46a42d4 --- /dev/null +++ b/src/Franzose/ClosureTable/Generators/stubs/migrations/migration-innodb.php @@ -0,0 +1,55 @@ +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}}'); + }); + } +} diff --git a/src/Franzose/ClosureTable/Generators/stubs/migrations/migration.php b/src/Franzose/ClosureTable/Generators/stubs/migrations/migration.php new file mode 100644 index 0000000..deef709 --- /dev/null +++ b/src/Franzose/ClosureTable/Generators/stubs/migrations/migration.php @@ -0,0 +1,52 @@ +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}}'); + }); + } +}