orptech-com / laravel-migration-partition

This package extends Illuminate to enable partitioned table creation within Laravel migrations.
https://orptech-com.github.io/laravel-migration-partition/
MIT License
24 stars 4 forks source link

Partitioned by hash not working #38

Open jamesRUS52 opened 4 days ago

jamesRUS52 commented 4 days ago
        Schema::createHashPartitioned('car_user', function (Blueprint $table) {
            $table->ulid('id');
            $table->foreignUlid('car_id')->references('id')->on('cars')->cascadeOnUpdate()->restrictOnDelete();
            $table->foreignUlid('user_id')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
            $table->integer('box');
            $table->timestampsTz();

            $table->index('car_id');
        }, 'id','user_id','user_id');

perfom migration


  Attempt to read property "autoIncrement" on null

  at vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php:232
    228▕      * @return string
    229▕      */
    230▕     public function compileAutoIncrementStartingValues(Blueprint $blueprint, Fluent $command)
    231▕     {
  ➜ 232▕         if ($command->column->autoIncrement
    233▕             && $value = $command->column->get('startingValue', $command->column->get('from'))) {
    234▕             $table = last(explode('.', $blueprint->getTable()));
    235▕ 
    236▕             return 'alter sequence '.$blueprint->getPrefix().$table.'_'.$command->column->name.'_seq restart with '.$value;

      +7 vendor frames 

  8   database/migrations/2024_10_21_092629_create_car_user_table.php:11
      ORPTech\MigrationPartition\Support\Facades\Schema::__callStatic()
      +27 vendor frames 

  36  artisan:13
      Illuminate\Foundation\Application::handleCommand()

``
ArdaKaraderi commented 3 days ago

Hi @jamesRUS52,

I think it's due to the use of ulid. The method in the package uses autoIncrement which is a part of numeric fields. As you are using ulid it fails to do so. We had some other discussions regarding the ID as well.

@asterissco - https://github.com/orptech-com/laravel-migration-partition/discussions/36 @briets - https://github.com/orptech-com/laravel-migration-partition/pull/25

If it's urgent for you and you have the availability, please feel free to create a PR that helps solve your issue. I am planning to rework these to improve the base methods in early 2025. Again, if you have the time, the introduction of the ability to skip ID assignments like @briets should be sufficient. (Needs to be for all partition types and not for a single one)

Kind regards,