I am running a set of migrations that denormalize one of my tables. I am running some code in one of the migrations that sets the ids in a new table based on the content of the current table.
For some reason, the id is not getting written correctly. To debug this, I would like to echo some of the variables out to the command line when I run the migration (in development). However, I have so far been unable to get those commands to work.
Yes, you can use all the usual ways (echo, var_dump, print_r). They will output normally to the command line in migrations.
If you suspect (as I did) that something about Laravel's migration system is silencing them, you are barking up the wrong tree.
Related
I tried to run a specific migration table from the controller using the following code
Artisan::call ("migrate:refresh --step=14");
but it does not refresh table 14, on the other hand it refreshes all the tables
.. ,
any suggestion !!
That is the purpose of migrate:refresh. It rolls back the migrations and then runs them:
The migrate:refresh command will roll back all of your migrations and
then execute the migrate command. This command effectively re-creates
your entire database
You may roll back and re-migrate a limited number of migrations by
providing the step option to the refresh command. For example, the
following command will roll back and re-migrate the last five
migrations
If you want to run run a specific migration the command would be:
migrate --path=/database/migrations/my_migration.php
This does however not sound like the best way to achieve whatever you are trying to achieve. Without further information it's hard to suggest an alternative plan for how to achieve this.
Edit: If you are trying to insert pre-defined data into a table you should look into using Database Seeders which sound much more to be what you are looking for.
I need to make a tool to Browser test my production system. I have read up all about Laravel Dusk and it seems like a perfect tool. However, I need to run tests automatically via schedule and have a dashboard with the results.
I can easily run the command php artisan dusk from the code using the Scheduler, however, how can I get the results? Is there a better option than simply parsing the Console Output from that command? Ideally I would have a way of getting the status of each test (whether it passed or failed) to be able to log, process and display all that information.
The Dusk documentation hasn't got any more information on running the tests programatically, it only has instructions to run via php artisan dusk.
Has anyone encountered this?
Thank you!
The way I have achieved what I needed is to use the command options for dusk/phpunit.
I used --filter=MyTestClass to single out which test I wanted to run, and --log-junit log.log to log the results for that test, which I then parsed via code as well to fetch the results. This allowed me to build a fully custom dashboard that was able to run each test individually, report the results, send notifications etc.
Not the prettiest solution, but it worked well for what I needed. If anyone encounters better way to achieve that (or just use Dusk in general as a browser/scraper outside phpunit) please do post a comment/answer!
I am the sole person in charge of a website that keeps track of records that other employees submit and compiles them into nice spreadsheets so that non-technical users can easily read them.
The other guy who used to work here quit unexpectedly, and I have to make a small, one-line change to the PHP code that he wrote, the problem is, when I edit the code, it does not seem to change anything. For example, I can completely delete the code that displays an error message, but that error message will still show up. There are other parts of the project that I CAN modify, like XML files and python programs, but the PHP does not seem to care if it is modified.
I vaguely remember a command like 'php artisan serve' but that doesn't seem to help either
After googling the problem, I came across several other commands like 'npm run production' and 'php artisan optimise' but those didn't work either.
Thanks for your help
Are you changing the code directly on the server? Or are you trying it local first? Is the change on a view-file?
Try php artisan cache:clear. It should clear all the caches and probably show your changes.
I am working with Symfony and Doctrine for the first time. I am curious: Is there a simple way to reverse a set of changes generated via a single running of the doctrine:generate:entity command?
I don't have any specific reason (yet) for asking this. I just imagine that it could potentially be helpful for me at some time in the near future, especially since my current version control only covers changes to the filesystem, omitting modifications to my sandbox's database contents -- which is relevant here.
In other words, some real equivalent for my imagined command doctrine:generate:rollback would be ideal. I'm assuming there's probably a way to do this type of thing.
Edit: TIL that the doctrine:generate:entity doesn't actually do anything to the database on its own. In many workflows, the doctrine:schema:update command does that after entities have been generated.
No, there is no Symfony or Doctrine command to do a rollback, but what doctrine:generate:entity really does is generating new php file with entity definition. So an actual rollback for doctrine:generate:entity is:
rm /path/to/your/entity.php
The answer is: No, there is no 'rollback' command, which removing all changes.
Do not forget that all changes in file system you can rollback via GIT (or other VCS).
I wrote a particularly long migration for my website, and unfortunately was caught altering it quite a bit (I know I'm supposed to write additional migrations, instead of altering preexisting ones, but this wasn't possible in this case).
This is a complex migration, so I wrote it into the safeUp() function, as it should be wrapped in a transaction. When I run the migration, everything seems to work perfectly. It shows me each SQL command as it runs, and then at the end, says it ran successfully. The migration appears correctly in the history. However, when I visit the database, I realize that the migration is only partially done. Which should be impossible because it was written in safeUp().
It should be noted that I was running many migrations at once, and that each one runs successfully. The only time I got it to work, I ran every other migration up until the one in question (using ./yiic migrate to timestamp), and then copy pasted the sql into phpmyadmin, and ran it manually. Boom, perfectly done.
Anyone run into this problem?
-- Edit: I believe the issue here was that Yii parses SQL comments in an interesting way when it runs inside the $this->execute('sql'), so that the SQL it was generating was not identical to the raw SQL.
-- Edit2: This is ages ago now, but I'm now learning about this bug https://github.com/yiisoft/yii2/issues/9894. I think it may apply to Yii1 as well, if anyone out there is reading this.