Skip to content

Commit

Permalink
Manually map models on migration instead of loading via directory (#1928
Browse files Browse the repository at this point in the history
)

Currently if you publish the migrations they can fail due to trying to
read a directory relative to the the vendor folder. This PR instead opts
to manually map the models to prevent this issue completely.

---------

Co-authored-by: alecritson <[email protected]>
Co-authored-by: Glenn Jacobs <[email protected]>
  • Loading branch information
3 people committed Sep 17, 2024
1 parent f3db113 commit c4381dc
Showing 1 changed file with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
<?php

use Illuminate\Support\Facades\Schema;
use Lunar\Base\BaseModel;
use Lunar\Base\Migration;
use Spatie\StructureDiscoverer\Discover;

class RemapPolymorphicRelations extends Migration
{
public function up()
{
$modelClasses = collect(
Discover::in(__DIR__.'/../../src/Models')
->classes()
->extending(BaseModel::class)
->get()
)->mapWithKeys(
$modelClasses = collect([
\Lunar\Models\CartLine::class,
\Lunar\Models\ProductOption::class,
\Lunar\Models\Asset::class,
\Lunar\Models\Brand::class,
\Lunar\Models\TaxZone::class,
\Lunar\Models\TaxZoneCountry::class,
\Lunar\Models\TaxZoneCustomerGroup::class,
\Lunar\Models\DiscountCollection::class,
\Lunar\Models\TaxClass::class,
\Lunar\Models\ProductOptionValue::class,
\Lunar\Models\Channel::class,
\Lunar\Models\AttributeGroup::class,
\Lunar\Models\Tag::class,
\Lunar\Models\Cart::class,
\Lunar\Models\Collection::class,
\Lunar\Models\Discount::class,
\Lunar\Models\TaxRate::class,
\Lunar\Models\Price::class,
\Lunar\Models\DiscountPurchasable::class,
\Lunar\Models\State::class,
\Lunar\Models\UserPermission::class,
\Lunar\Models\OrderAddress::class,
\Lunar\Models\Country::class,
\Lunar\Models\Address::class,
\Lunar\Models\Url::class,
\Lunar\Models\ProductVariant::class,
\Lunar\Models\TaxZonePostcode::class,
\Lunar\Models\ProductAssociation::class,
\Lunar\Models\TaxRateAmount::class,
\Lunar\Models\Attribute::class,
\Lunar\Models\Order::class,
\Lunar\Models\Customer::class,
\Lunar\Models\OrderLine::class,
\Lunar\Models\CartAddress::class,
\Lunar\Models\Language::class,
\Lunar\Models\TaxZoneState::class,
\Lunar\Models\Currency::class,
\Lunar\Models\Product::class,
\Lunar\Models\Transaction::class,
\Lunar\Models\ProductType::class,
\Lunar\Models\CollectionGroup::class,
\Lunar\Models\CustomerGroup::class,
])->mapWithKeys(
fn ($class) => [
$class => \Lunar\Facades\ModelManifest::getMorphMapKey($class),
]
Expand Down

0 comments on commit c4381dc

Please sign in to comment.