lucabecchetti / laravel-mysql-partition

Useful Laravel package to easily work with MySQL Partition
Other
139 stars 26 forks source link

Separate DB connections feature request #10

Open ipearx opened 2 years ago

ipearx commented 2 years ago

Hi I can't seem to create a partition by range on a separate DB connection e.g.

            Schema::connection('tracking')->partitionByRange('tracking', 'UNIX_TIMESTAMP(created_at)', [
                new Partition('p'.$twodaysago, Partition::RANGE_TYPE, $twodaysago),
                new Partition('p'.$yesterday, Partition::RANGE_TYPE, $yesterday),
                new Partition('p'.$today, Partition::RANGE_TYPE, $today),
                new Partition('p'.$thenextday, Partition::RANGE_TYPE, $thenextday),
            ]);

gives the error: Call to undefined method Illuminate\Database\Schema\MySqlBuilder::partitionByRange() I'd say this would be a good feature to add if not yet implemented, as many using it will have a dedicated DB server. For me it means I'll have to remove the package and do it with a manual DB call.

PhillipMwaniki commented 1 year ago

Hey, I work with multiple database access and the best way to work with this is to switch your default connection i.e. DB::setDefaultConnection($instance), do the transaction and then switch it back.

For migrations, you pass in the --database flag at the end.