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.
Related
I know that I can run specific migrations using execute with up / down and version number, ie
doctrine:migrations:execute YYYYMMDDHHMMSS --down
My question then - is there an easier way to simply run the next or previous migration without having to look up version numbers?
Ideally I would like something like
doctrine:migrations:execute --down n
Where n is the number of migrations to run from current in the specified direction.
(same idea as rake db:rollback STEP=n)
Closest thing to what I was looking for is:
doctrine:migrations:migrate prev
doctrine:migrations:migrate next
These cannot be used in conjunction with n though, so if you want to do more than 1 you need to use doctrine:migrations:migrate with the version number you want to go to.
i usually just call status, which shows if there any new ones. If so then I call migrate, and it runs all the new ones. See Docs here http://docs.doctrine-project.org/projects/doctrine-migrations/en/latest/reference/introduction.html
How do can I log every artisan calls?
Ex:
Logging all the php artisan serve, migration and seeds
and save it to a database?
I have no idea why you need it but here is it. The easiest way (but not the best) - is to modify "artisan.php" with simple code like this:
ArtisanModel::create(['command' => $_SERVER['argv'][1]];
just after $kernel var
It mean you have to create new Model and store $_SERVER['argv'] result in it.
Another way (the better one) is determine is your application running in CLI mode somewhere in ServiceProvider
I've created some migration and seed files using bake, but now the dba guys say i should use an sql script to create and populate the tables. Is there a fast way of converting the files, without having to write the script by hand?
Yes, of course. Connect to SQL Server with SQL Profiler and run your current migration. Written profiled script is the converted one. You need only set appropriate Profiler's filter properties.
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.
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.