How to atomatically apply migrations that comes from Yii2 extensions - yii2

I have installed an extension for Yii2 dektrium/yii2-user using composer using it's "require" section. This extension contains migrations for database. Is it possible to apply migrations from this extension using console syntax not like this:
php yii migrate --migrationPath=#dektrium/yii2-user/migrations
but run all migrations automatically by using a simple command like:
php yii migrate
Is it possible to tell composer where the concrete extension contains it's migrations?

If you want to make this process automated, you can use scripts property of composer. For more information you can see https://getcomposer.org/doc/articles/scripts.md. In your case you can do your goal with something like this on composer.json:
{
// Some codes are here
"scripts": {
"post-update-cmd": [
"php yii migrate --migrationPath=#dektrium/yii2-user/migrations"
],
"post-install-cmd": [
"php yii migrate --migrationPath=#dektrium/yii2-user/migrations"
]
},
// Some codes are here
}
I prefer to save all commands that must be run after install -or update- on a file (for example file named commands) in the root of project, like this:
#!/usr/bin/env bash
./yii migrate/up --migrationPath=#vendor/dektrium/yii2-user/migrations
./yii migrate/up
./yii migrate/up --migrationPath=#app/modules/rules/migrations
./yii migrate/up --migrationPath=#app/modules/formsaz/migrations
./yii migrate/up --migrationPath=#app/modules/todo/migrations
./yii formsaz/rules/init
./yii husky/rules/init
and on composer.json file put its name:
{
// Some codes are here
"scripts": {
"post-update-cmd": [
"sh commands"
],
"post-install-cmd": [
"sh commands"
]
},
// Some codes are here
}
So each time after composer install or composer update, all commands will be run (and it's useful on teamwork).

I found only one good solution - Install yii2 extension https://github.com/dmstr/yii2-migrate-command
Now i can easily use command "php yii migrate" and don't worry that someone from my team doesn't apply required migrations.
Thanks others for help! If u find more appropriate solutions, please share =)

Yii2: Allow Migrate From Multiple Path

Related

PhpStorm file watcher "Error: Cannot find module" with babel plugins in a rollupjs script (no executable available), plugins globally installed

I can't seem to be able to resolve this, hoping someone might be able to help.
I have configured a file watcher to check for changes in a source directory. When a change is found, it runs the following tool: -
Program: C:\xampp\htdocs\currentproject\packages\node_modules\.bin\rollup
Arguments: -c C:\xampp\htdocs\currentproject\packages\source_directory\rollup.config.js
It is finding the rollup script OK but then I run into an issue as the rollup.config.js file calls babel as a plugin: -
import babel from "rollup-plugin-babel"
plugins: [
babel({})
],
babel.config.js: -
module.exports = {
presets: [
'#babel/preset-env',
'#babel/preset-react',
],
plugins: [
"#babel/plugin-proposal-class-properties",
"babel-plugin-styled-components"
],
}
It finds this config file OK but then I get the following error: -
(plugin babel) Error: Cannot find module '#babel/plugin-proposal-class-properties' from 'C:\xampp\htdocs\currentproject'
Now I understand how to configure external tools in PhpStorm but #babel/plugin-proposal-class-properties does not have a .bin/executable, only a .js file. I have also tried installing it globally via yarn and created a Windows environment variable to point to the global yarn directory but to no avail - I still get the same error.
Can anyone help me with this?

PhpStorm not recognizing file paths

I just picked up a project from another developer, and I don't know why, maybe this is because it's my first time remotely connecting to an EC2 instance, but PhpStorm isn't recognizing parts of the file paths in the "use" namespace section.
However, the code runs very well with no errors on the EC2 instance.
Here is what it looks like:
Why are "Common", "ORM", "Validator", "Constraints", "User", and "Collections" in red?
Is there any extra configuring I need to do in PhpStorm?
I know that these directories are there, for example the "use App\Entity\User" namespace is accounted for in the "User" entity file:
You need to install PHP Annotations plugin. Plus it looks like you haven't run composer install against the project's composer.json

Accessing environment variables in package.json

Recently I started working on a pretty old application where API endpoint URL differs on each system.
Right now, my package.json looks like this:
"start": "cross-env API_ENDPOINT=http://localhost:5000/api/v1 react-scripts start"
The problem is, this value is currently static so when I deploy the code into Heroku, it tries to connect my localhost. Instead, I'm looking to do something like this:
"start": "cross-env API_ENDPOINT={thisShouldBeDynamic} api/v1 react-scripts start"
Is there any way to do it?
Ps. react-app-scripts version is ^0.4.0 so I cannot rely on .env and believe me, you wouldn't want to update it.
JSON format doesn't support templating itself, so you need to create a script which will opens config.json, update it and save back to same file.
You can start from https://www.npmjs.com/package/config-template and create your own template filler which retrieve env variables you need and add them to config file, then same a file.
You can alter your installation before it starts up with the postinstall NPM hook. https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process
For instance:
"scripts": {
"postinstall": "node ./ops/heroku-build.js"
}
And then in that script, simply read the appropriate env variables. process.env holds all the Heroku environment variables. Use those to edit your package.json.

Is it possible to use Composer to manage Wordpress databases?

I am trying to use Composer for my Wordpress workflow and was wondering if there is a way for Composer to grab a MySQL database from my S3 bucket? The idea here is that I want to develop Wordpress websites locally starting from a backup copy of a database. Was hoping to find a way to automate this through Composer.
You can define custom scripts for composer, and tell it what you want to do.
For example, if you wanted to pull it from S3 and import it using the mysql command line utility, you could add something like this to composer.json:
"scripts": {
"refresh-db": "aws s3 cp s3://my-bucket/db-dump.sql /tmp/db-dump.sql && mysql -hlocalhost -uroot my_db_name < /tmp/db-dump.sql"
}
Then run composer refresh-db to execute it.

Selenium Builder tests with Jenkins and Github

My goal: setup a simple test framework using Selenium Builder as a FF plugin, GitHub and Jenkins. Retain the test files in .json format. I don't wish to go near java or maven for now.
My current setup: - Selenium Builder add-on for FF28 with Github plugin - Jenkins 1.567 with SeleniumBuilder plugin - Jenkins job setup as a freestyle project, building when a push is made to Git repo and 'Invoke selenium Builder script' as a build step with 'Script file' pointing to root of my test folder(.json scripts)
I can run my .json scripts using se-interpreter from command line using java -jar SeInterpreter.jar example_test.json
What I need to know is - how do I configure Jenkins and the se-interpreter-config file so I can run from Jenkins? currently my interpeter config file looks like this:
{
"type": "interpreter-config",
"configurations": [
{
"settings": [
{
"driverOptions": {
"host": localhost,
"port": 4444
},
"browserOptions": {
"browserName": "firefox",
}
}
],
"scripts": [
"mySeleniumBuilderTests/tests/*"
]
}
]
}
This is how I did.
1. Add the Selenium Builder plugin to your Jenkins.
2. Upload your test script (html or json) to git repo.
3. In Build, select Invoke Selenium Builder Script.
4. Put your script file name there.
5. Build with the URL of your git repo.
Done.