Is it possible to call some facade method from propel migrations ?

UKKQKJ9FX
UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet
edited June 2023 in Propel ORM

Hi, Is it possible to call some facade method from propel migrations ?

Tagged:

Comments

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    $foo = new FoobarFacade()
    $foo->bar() πŸ™‚

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    (not saying it's a good idea though ... πŸ™‚ )

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    Tried that lol, Warning: require(APPLICATION_ROOT_DIR/config/Shared/stores.php): failed to open stream: No such file or directory in /var/www/vendor/spryker/kernel/src/Spryker/Shared/Kernel/Store.php on line 152

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited January 2020

    oh I guess it isn't bootstrapped for zed, perhaps, maybe just Propel

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi Filip, the migration files are executed by Propel directly. So there is no Spryker context and therefore you cannot use Facades here.

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UKGT7RC7P Direct instantiation of Facades is never a good idea because then eg there is no factory. If you need a facade without DependencyProvider then this is the offical way to get it:

    \Spryker\Zed\Kernel\Locator::getInstance()->customer()->facade();
    
  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    ah good to know πŸ™‚

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    (of course I never instantiated a facade directly ...)

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    πŸ˜„

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    Filip, in case you need a data migration and the data will be mandatory then you need three steps:

    1. Adjust the schema (e.g. add a column and set required=β€œfalse”)
    2. Implement your data migration somewhere else (e.g. in a Zed controller or CLI command. It’s throw-away code anyway.
      Migrate the schema and migrate your data.

    3. Adjust the schema again (e.g. set required=β€œtrue”)

  • rshopin
    rshopin Senior Solution Architect Sprykee Posts: 32 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited January 2020

    @UKKQKJ9FX in case if you need some data migration functionality you can use Installer plugins, check:
    \Spryker\Zed\Installer\Dependency\Plugin\InstallerPluginInterface
    and
    \Pyz\Zed\Installer\InstallerDependencyProvider

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks, will try

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    Are you suggesting just to manually run command to migrate data or can command be run from migration? @UKU1E0ENB

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    Command can be run during propel:install

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    But you need two deployments for this special case of data migration.

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    I personally prefer to have the propel migration files on gitignore so that they are generated on the fly during the deployment. This makes life so much easier when you switch branches during developments or on staging environments. In this case there is no chance to manipulate these files.

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    How do you run them during propel:install, from the shell or? It can not be ran from code inside migration ? What about migration down here

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    propel:install (or the specific commands behind) should be part of each deployment. Just look into the recipes.

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - Cadet

    I never reverted a migration because it’s not safe anyway.

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    okay, thanks πŸ˜„

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    Can I run the command automatically with the migration during the deploy

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    so I don't have to go to container and exec it manually

  • UKJND3A3H
    UKJND3A3H Posts: 123 πŸ§‘πŸ»β€πŸš€ - Cadet

    yep. there are different approaches though. we prefer generating the migration files, commit them to repo and β€œonly” process the existing ones on deployment. I heard others let propel do the calculation of the diff and the application of the generated migration files during deployment. that removes awareness and visibility of changes to be expected imo

  • UKKQKJ9FX
    UKKQKJ9FX Posts: 38 πŸ§‘πŸ»β€πŸš€ - Cadet

    I think you didn't quite get the question.
    I am talking about sprykers console command,
    I am using that command (console command) I wrote to transfer data from one table to another existing table that uses json as a value in certain columns so it would be hard to write raw sql queries for that. So after deploy I have to execute that command manually but I don't want to.
    Any ideas ? ( Would like to combine that with propel migration)