Git Product home page Git Product logo

Comments (7)

nikophil avatar nikophil commented on June 21, 2024

Hi @lsv

I think you can leverage global state here.

I have a similar problem: I need some sql views to be created in order to be used in the tests.

I'm using an invokable service to generate them:

// /config/packages/zenstruck_foundry.php

$containerConfigurator->extension('zenstruck_foundry', [
    'global_state' => [
        ViewsGenerator::class,
    ],
]);

and it gets created before each test (actually, before the very first test of the suite, since I'm using dama)

from foundry.

lhapaipai avatar lhapaipai commented on June 21, 2024

Thank you @nikophil for your answer and the tip,
But I think the @lsv issue and the mine 😄 is that createSchema method will fail if we haven't enabled PostGIS extension.
The extension offers a set of functions and types that are used to generate our tables.
global_state is a bit too late.

// vendor/zenstruck/foundry/src/Test/ORMDatabaseResetter.php
final class ORMDatabaseResetter extends AbstractSchemaResetter
{
    // ....

    public function resetDatabase(): void
    {
        $this->dropAndResetDatabase();

        // we need to make this sql query here 'CREATE EXTENSION postgis';
        // because our schema contain PostGIS functions
        
        $this->createSchema();
    }

    // ....
}

Dama couldn't help us either because resetDatabase seems to be called in the beforeClassMethod.

from foundry.

nikophil avatar nikophil commented on June 21, 2024

Hi @lhapaipai

indeed, you're right!

Maybe you could enable migrate mode for the database resetter?
You can look at this issue: #477

This comes with a performance cost, which makes dama almost mandatory.

(it was exactly the same problem, and I gave exactly the same wrong answer 🤡 )

from foundry.

lhapaipai avatar lhapaipai commented on June 21, 2024

Thank you @nikophil , I imagine this comes with performance cost, but at least it solves the problem !!

from foundry.

nikophil avatar nikophil commented on June 21, 2024

If you use dama, the performance cost is really limited, since the migrations are only ran once.

Maybe this whole problem could be solved by introducing some kind of events in the database creation process

WDYT @kbond ?

from foundry.

lhapaipai avatar lhapaipai commented on June 21, 2024

ok,
I think it could be super useful 😄 !!

from foundry.

kbond avatar kbond commented on June 21, 2024

WDYT @kbond ?

Yeah, I feel like this makes sense. I believe we've hardcoded out own platform-specific logic to the reset database process. These could perhaps be moved to events also.

from foundry.

Related Issues (20)

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.