I wanted to apply migrations, but it won't let me do that.
cmd looks like this:
D:\web\website>yii migrate --migrationPath=#yii/rbac/migrations
Yii Migration Tool (based on Yii v2.0.35)
Total 5 new migrations to be applied:
sjaakp\pluto\migrations\m000000_000000_init
m140506_102106_rbac_init
m170907_052038_rbac_add_index_on_auth_assignment_user_id
m180523_151638_rbac_updates_indexes_without_prefix
m200409_110543_rbac_update_mssql_trigger
Apply the above migrations? (yes|no) [no]:
D:\web\website>
It won't let me type 'yes' to apply to the migrations.
Anyone an Idea what I can do?
Thanks.
Ustmaestro gave a helpful answer:
I dont know wath is the problem with your terminal, but You can do it
by applying yes default using with --interactive=0 in migration
command like following: yii migrate --interactive=0
--migrationPath=#yii/rbac/migrations
You can customize migration to run without confirm by setting interactive mode to false.
So add --interactive=0 to your migration command.
For more information see Customizing Migrations.
Related
I have started using yii 2.0.16 version. When I made migration command in order to create initial user table, it didn't work. Instead, it showed view like this:
Can you help, please
I am developing Java web application what based on Spring Framework, MySQL, JPA. I have a problem when try to persistence data from HTML form to SQL database, then I try to debug and fix. I am using IntelliJ IDEA Ultimate 2017.1. I catch error:
Cannot resolve column 'product_name' This inspection controls whether
the Persistence ORM annotations are checked against configured
Datasources
This is screenshot:
How to fix it?
For those who just want to disable this check, go to
Intellij IDEA -> Preferences -> Search "Unresolved database references in annotations" and uncheck it.
(macOS Mojave and Intellij Ultimate 2019.3)
This will disable the inspection and remove all the "Cannot resolve column…" errors on the #Column annotations. Intellij will stop checking if the String column names exist in the database tables. Do it at your own risk.
Open Persistence tool windows, right click on module, then set DataSource. IntelliJ IDEA will validate source code by real SQL database.
You have to manage your data sources. I followed the steps detailed here
https://www.jetbrains.com/help/pycharm/managing-data-sources.html.
In my case, I did the following (I am using Pycharms, but I assume the process is similar for other Jetbrains IDEs):
Bring the Data sources and drivers window by going to view > tool windows > database
Click the wrench icon to configure the db connection
Configure it, and try that the connection works with Test Connection
Pycharms should now autocomplete fields in the db.
If it still doesn't work:
try restarting Pycharms.
go to options (command + ,), then search for SQL, select menu SQL Resolution Scopes, and try adding a scope by clicking +, then selecting your current project folder as path, and your db as the resolution scope
I found a TEMPORARY work around for this bug.
Please before you follow my workaround do exactly what #Benjamin Crouzier's answer suggests. THEN, go to any of the unresolved columns, right click it and they click execute. and Boom annoying warning SOLVED :)
After trying all the solutions above, I solved this by clicking Refresh in the database tool window.
I need to setup demo sites quickly with demo data, including hourly reset of data for a public demo site. Since our data uses timestamps relative to "now" (e.g. archived_timestamp), we cannot just restore an sql dump with fixed timestamps.
My idea is to use Yii2 migrations for that task with PHP code generating timestamps and inserting the demo data.
How to achieve that?
Are Yii2 migrations the right tool for that?
Is it recommended to store the migration file in a seperate subdirectory that our demo setup does not interfere with ordinary "migrate/up" and "migrate/down" processes?
Is this migration bound to a file naming scheme or can this be e.g. demo-data-setup.php ?
Are Yii2 migrations the right tool for that?
Could be if you need a proper sequence of sql command and instruction for create and populate a specific set of table and data you can use the funtcion up for creation an popluation and the function down for drop delete (or delete) what you need.
I*s it recommended to store the migration file in a seperate subdirectory that our demo setup does not interfere with ordinary "migrate/up" and "migrate/down" processes? Of course
Is this migration bound to a file naming scheme or can this be e.g. demo-data-setup.php ? In yii2 (but also in the other migration tools ) the migration file are related to a proper template, tipically datetime_migration_name.php
But for my experience for a proper and recurrent create/populate and drop/update/delete could be useful in some situation use a controller, especially if these activities are to be launched by web page or a URL without having to launch console commands use a controller with the appropriate action can be even up and down and possibly a view to an appropriate echo the results of operations
Yes, you could assign command name using controller map, configure migration path & table and use it without interfering with the original migration command.
In the console app's config, add a controller map with demo
'controllerMap' => [
'demo-setup' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => '#common/migrations/demo',
'migrationTable' => '{{%demo_setup_migration}}'
],
cd to your console app directory and use demo-setup command as you would use migrate command.
./yii demo-setup/create schema
./yii demo-setup/create sample-data
./yii demo-setup
You may wish to setup a cron job to re-create db and apply migration or re-apply migration to existing db to override demo data.
Are Yii2 migrations the right tool for that?
As long as you store your demo migrations in a separate location than your main migration. To be honest, when I start a new Yii2 project I always start with creating migrations for demo data (I also create the first user with migration). I usually use faker, and some of my own classes to generate demo data.
Is it recommended to store the migration file in a seperate subdirectory that our demo setup does not interfere with ordinary "migrate/up" and "migrate/down" processes? Yes, you should!
Is this migration bound to a file naming scheme or can this be e.g. demo-data-setup.php? From the official Yii2 documentation about naming migrations:
Note: Because the name argument will be used as part of the generated migration class name, it should only contain letters, digits, and/or underscore characters.
Ps.: don't overengineer your projects
Are Yii2 migrations the right tool for that?
No, migrations are for database structure changes (add a column, set index,..) more than fill tables with data. In your case, I would write a component, that have delete / create function for every model you need to restore. Then, you can call your component with a cron task.
You can use fixtures.
Fixtures are an important part of testing. Their main purpose is to set up the environment in a fixed/known state so that your tests are repeatable and run in an expected way. Yii provides a fixture framework that allows you to define your fixtures precisely and use them easily both when running your tests with Codeception and independently.
I am building a product that is based on the Yii2 advanced template.
As part of this product and its future deployments, I am trying to automatically create the tables related to Authorization in a regular Yii2 migration.
E.g, when the end user installs the product and runs the regular Yii migration commands he should have a fully functional user management AND authorization active.
For authorization to work, the Yii2 RBAC documentation page states that 4 tables are needed (auth_*). The documentation states that they are created by running the following migration:
yii migrate --migrationPath=#yii/rbac/migrations
I'd like to offset this extra hassle from the end user by running this specific migration code for him inside a regular migration that will be stored in common/migrations.
Any easy solution for this?
I have created a migrate.sh file where I put my migration commands that I need to run. This allows me to migrate from multiple places in the same time. It is quite simple, take a look here: https://github.com/Mihai-P/yii2-app-advanced/blob/master/migrate.sh
Instead of running ./yii migrate/up i just run sh migrate.sh that will update everything from any place.
The actual point of this is: you do not have to stick to exactly what Yii gave you. That is just a template for you to build on. Fork it, modify it, make it your own.
Try to add in console/config/main.php:
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => [
'#console/migrations',
'#yii/rbac/migrations',
]
]
],
Another approach (not using *.sh file) is to copy the rbac_init migration to your migrations folder:
cp vendor/yiisoft/yii2/rbac/migrations/m???????_rbac_init.php console/migrations/
Now, when you run php yii migrate it will be included the rbac_init migration.
I know this is pretty old question, but here is easy solution, create migration file and have this code in that file
<?php
require(Yii::getAlias('#yii/rbac/migrations/m140506_102106_rbac_init.php'));
/**
* Class m220225_133725_init_rbac
*/
class m220225_133725_init_rbac extends m140506_102106_rbac_init
{
}
First, thanks for your help.
As a noob, I've been happily chugging along this well-known tutorial:
http://ruby.railstutorial.org/chapters/static-pages#top
and I'm caught in a section where I enter
rspec spec/
where I receive 2 errors. The 2 errors are in the format of
PagesController GET 'home' should be
successful
Failure/Error: Unable to find matching line from backtrace
Mysql2::Error:Unknown database 'xyz.rb'
where "home" is the name of the action/page. The xyz.rb is the arbitrary
database name I have listed under the test section in database.yml. I
have already raked the database.
I'm pretty sure my problem has to do with how I'm not going with the
sqlite3 in the tutorial but instead with mysql2. The resources I have
managed to find only give guidance on what to input for the development
section in database.yml, but not for the rest of the sections like
"test". So, my question is, what exactly does this error mean, how to
fix it, and how should I configure my database.yml file? I tried
entering a file I see in my db folder like schema.rb, but this renders
the same error.
Thank you very much for your help.
You have two options:
Set up another sqlite database, as is default with a new rails application, or
Create another MySQL database, the same way you set up your development database, with a different name (such as test) and use that for testing.
Here's my database.yml file from the Rails Tutorial that uses SQLite for all the databases; you should be able to copy the test section if you decide to go with #1 above.