Giter VIP home page Giter VIP logo

Comments (5)

dereuromark avatar dereuromark commented on May 24, 2024

Can you propose a code change that would work for you?
Bear in mind that you can always set up a test connection - which you should for dev env.

And for prod it should auto use the connection defined.
maybe you forgot that:

'DatabaseLog' => [
        'datasource' => 'default',

This way it uses the default connection for sure and will not try to open an alternative one.

If you want to bypass database log for local dev, you can also do this in bootstap_cli file:

if (Configure::read('debug') || Configure::read('App.isLocal')) {
    $logTypes = array_keys(Configure::read('Log'));
    foreach ($logTypes as $logType) {
        Configure::write('Log.' . $logType . '.className', 'File');
    }
}

But you said your problem is specific to prod.

from cakephp-databaselog.

r34117y avatar r34117y commented on May 24, 2024

Hi Mark! Thanks for answering!

'DatabaseLog' => [
        'datasource' => 'default',

exists in my app.php.

The error itself is thrown inside CakePHP class: vendor/cakephp/cakephp/src/TestSuite/Fixture/TestFixture.php

Stack Trace:
#0 /var/www/weba_konfigurator/vendor/cakephp/cakephp/src/TestSuite/Fixture/TestFixture.php(182): Cake\Datasource\ConnectionManager::get('test')
#1 /var/www/weba_konfigurator/vendor/cakephp/cakephp/src/TestSuite/Fixture/TestFixture.php(145): Cake\TestSuite\Fixture\TestFixture->_schemaFromFields()
#2 /var/www/weba_konfigurator/vendor/dereuromark/cakephp-databaselog/tests/Fixture/DatabaseLogsFixture.php(71): Cake\TestSuite\Fixture\TestFixture->init()
#3 /var/www/weba_konfigurator/vendor/cakephp/cakephp/src/TestSuite/Fixture/TestFixture.php(113): DatabaseLog\Test\Fixture\DatabaseLogsFixture->init()
#4 /var/www/weba_konfigurator/vendor/dereuromark/cakephp-databaselog/src/Model/Table/LazyTableTrait.php(63): Cake\TestSuite\Fixture\TestFixture->__construct('default')
#5 /var/www/weba_konfigurator/vendor/dereuromark/cakephp-databaselog/src/Model/Table/DatabaseLogsTable.php(55): DatabaseLog\Model\Table\DatabaseLogsTable->ensureTables(Array)

For now I've solved the problem by creating test connection on prod. To be honest it's the first time I see testing related stuff injected into the code at the app level (and during initialization of class!). It's a bit strange for me ;)

The solution that comes to my head first is to add option in config file to omit all the test suite related stuff (and even make it default). In ma case I had to run plugin migrations manually anyway, but I didn't have time to explore why.

If I don't get something, you can close this topic. If I have some spare time I will try to make a pull request with my proposition.

from cakephp-databaselog.

dereuromark avatar dereuromark commented on May 24, 2024

Why using fixtures in prod?

from cakephp-databaselog.

r34117y avatar r34117y commented on May 24, 2024

Hi there! Sorry for a late reply, but honestly I forgot about that topic. I came here to report another issue, so I will reply to this one too.

Why using fixtures in prod?

I'm not using fixtures in prod, but I have them as a part of the repository, so the test-related files do exist in production environment. The error stacktrace is:

  • DatabaseLogsTable calls $this->ensureTables(['DatabaseLog.DatabaseLogs']) during initialization. (line 55)
  • ensureTables() creates classname using App::className($name, 'Test/Fixture', 'Fixture'); (LazyTableTrait.php, line 58) - I don't get why plugin is expecting that those classes exist, but ok, I have those fixtures
  • ensureTables() tries to instantiate fixture class using $fixture = new $class($this->getConnection()->configName()); (LazyTableTrait.php, line 63)
  • during initialization the framework's Cake\TestSuite\Fixture\TestFixture::init() is called, and it calls it's _schemaFromFields() method
  • _schemaFromFields() gets it's own connection. which is obviously "test", because fixtures system is designed for dev only.

So once again my problem is: you are using test-related parts of the framework inside the test-unrelated plugin, which is bad solution IMO.

But don't worry - it's a small plugin, thanks for doing it. I hope I'll manage to make PR ;)

from cakephp-databaselog.

dereuromark avatar dereuromark commented on May 24, 2024

All right, looking forward to your PR.

Maybe the docs should be more clear that if you are using
https://github.com/dereuromark/CakePHP-DatabaseLog/blob/master/src/Model/Table/LazyTableTrait.php#L45 and SqLite auto build feature, that this app must not be designed for prod.
This is only meant to get started quickly for local test projects or POC apps, never for real live prod apps.

from cakephp-databaselog.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.