Torann/laravel-currency

Table doesn't exist on installing

ricardobarantini opened this issue ยท 17 comments

After this:
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"

I receive this:

[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist (SQL: select * from `currencies`)

[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist 

๐Ÿ‘ same issue

+1

Just change 'driver' => 'database', to 'driver' => 'filesystem', in src/config/currency.php.

Then everything works fine. I created a pull request.

Unfortunately that is not a solution for users who are using database as the driver.

Why not, you can change it afterwards. It's just the bundles default config.

Yes that is only a fix for someone who freshly installed the package, did the migration and publish the config for override.

When it comes to deployment to production that where it will start breaking and artisan will crash as well.

Doing testing will not work if a testing DB is generated from the migrations.

You're right. The Problem is the getCacheCurrencies() function which is calling the all method of the driver.

A simple if ($this->database->hasTable($table)) would solve the issue. But I don't know the code of this bundle so @Torann should decide ^^.

Indeed!

As a temporary fix I am overriding the getCacheCurrencies and have the below condition:

    if ((App::runningInConsole() && ! App::runningUnitTests()) || (App::runningUnitTests() && !Schema::hasTable('currencies'))) {
        return ...
    }
    return parent::getCacheCurrencies();

+1

I've just wrote a couple line to prevent the code to crash. I would like to know what you guys think, specially @Torann , I leave the full function, even though I only have added the first block of if.

public function getCacheCurrencies()
{
    if(is_a($this->getDriver(), 'Torann\Currency\Drivers\Database')){
        $table_name = $this->getConfig('table', 'currencies');

        if(!Schema::hasTable($table_name)) {
            return $this->currencies;
        }
    }

    if (config('app.debug', false) === true) {
        return $this->currencies = $this->getDriver()
                                        ->all();
    }

    return $this->currencies = $this->cache->rememberForever('torann.currency', function () {
        return $this->getDriver()
                    ->all();
    });
}

The bit of code that I proposed it doesn't seem to be good enought. It's throwing a new set of errors. Anyone has any update on this issue?

same problem till now!

I'm looking into this now. From what I remember I ran into this problem with another project I had and fixed it.

I just released a new version. http://lyften.com/projects/laravel-currency/doc/upgrade.html

It uses a middleware to handle currency switching so the database isn't trying to be called when the app boots.

Anymore problems with this? Just reopen and I'll look it over.

I removed my database, so it's completely empty now and I can't even run artisan commands with message 1146 Table dbname.currencies doesn't exist (SQL: select * from currencies).

Version 1.1.0