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.
Related
I'm able to create a new service which creates a table in the MySQL DB just fine, but the feathersJS model file simply creates 1 text field in the model by default,
when I modify the fields add more etc...this does not reflect in the database.
Is there a migration script i must run ? can someone show me how to run a command that will reflect the changes i make to the model so I can sync the two.
right now I have to manually modify the table to match the model.
In your src/sequelize.(js|ts), there should be a call like sequelize.sync(). This updates the structure of the database according to the model definitions every time the app gets started. So in theory, restarting the app should be enough.
If that doesn't work, try .sync({ alter: true }) or even .sync({ force: true }). (This might be fine during initial development, but is not recommended for production use as it can result in data loss. See also the docs about .sync() options.)
You already mentioned Migrations, which would be a better alternative for sure. With Umzug they can be automatically executed during startup as well.
I am trying to do code migration from one environment to other(Say DEV to STG) without using PMT Tool.
I have the code for doing the promotion in command Line. But the thing is I am trying to promote in the server itself without taking any backup. So i am in need of two things.
1)Path of the report in the server. In PMT we are able to see ther report under particular folder so it has a proper path. Similarly how can i find the path of a report at server level
2)Could the code only be used if there is a BIAR file?
The code which i am talking about:
action=promote
importLocation=Path // tHE DOUBT PART
CMS="CMS name:port number"
Destination_CMS="CMS name:port number"
Destination_userName="username"
Destination_password="password"
Destination_authentication="secEnterprise"
Read the admin guide.
The command-line BIAR utility does not support direct system-to-system migrations. You can only export to BIAR or import from BIAR.
The importLocationparameter specifies the location of the BIAR file to import. It has nothing to do with the location of objects in the CMS.
You don't specify reports to migrate using their path, but rather with a CMS query. See the exportQuery parameter.
You can also use the command line tool to perform a migration using a saved PM job. So, you would still use PM to create an export job (and select the objects to include), but then use the command line tool to perform the migration
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
{
}
I have the following problem:
I Am using a Django framework.
One of the parts in a system (non-django) writes to the database, in the same database that django is using.
I want to have a signal when an object is being saved. It's a django model object but not saved via django, but directly in the mysql database.
Is there a way django can watch save-actions in his database when it's not being saved by django?
The neatest way would be: create an Api, and let the save action run through this api. The save signal can than be django default. (but this depends on some work of externals... so not the prefered route... for future development it sure is).
Another option is to implement celery and create a task that frequently looks whether one of the saved objects has had no follow up..... (also quit some puzzling I guess to get this up and running)
But there might be an easier... for me unknown?
I saw django watchdog solutions for file systems... not for databases (probably because django has this build in... when properly done through django)
to complex it: I test and develop locally with sqlite .... but the save signal I can put in my tests without needing to get this locally working.... as long as it works in mysql, I Am happy.
You can try this solution:
Create a new table 'django_watch' with one column 'object_id' (add other columns like 'created_datetime' etc according to your standards);
Lets say your main table is 'object'. Add a mysql trigger for the INSERT event on this table.
You should add an extra insert query inside the trigger to insert the object_id into 'django_watch' table.
Now you can have a cronjob that will be inpecting the new table 'django_watch' (for updations in Django objects) and perform necessary actions. You can run this cronjob continuously with some 1 minute delay (upto you).
In the end, I wrote an api that can be called by the thirdparty module. I delivered the code to logon on django using c-code to this api and call the GET of this api. (using django rest framework). This api just saves the object (the id given in the url), and from there on it's default django. The only thing the third party had to do is build in my code to call the api as well....
Maybe not the best solution, but the best to implement for my problem....
I have a question about how to render the sql schema with fluent nhibernate.
I have searched alot and used a couple of things but i dont know how to render it. I´m only building the ground of my website, the core. And now i want to create the database from my mappings. How do i do that? Is it with testrunning or what?
If i build the solution i don´t get any sql file i have also tried export it to hbm files to use schema tool export but dont get it to work.
have tried
Fluent NHibernate (1.2.0.712) export mappings to HBM not working / not respecting conventions
and
https://stackoverflow.com/questions/5244257/build-schema-with-fluent-nhibernate
and alot other links.
What do i have to do to get the sql file? every site give almost the same code but they don´t tell how to render it. How to execute the process to retrieve the file..
can anyone tell me? i can build it by my self but i want to try this function!
best regards
You can create the database using the SchemaExport.Create method:
// this NHibernate tool takes a configuration (with mapping info)
// and exports a database schema from it
new SchemaExport(config)
.Create(true, true);
If you want to see the generated SQL, you can use the ShowSql method, but this is not required to create the database.
_sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard
.UsingFile(SqliteDatabaseFullPath())
// Display generated SQL in Output window
.ShowSql()
)
...
It's been my experience with NHibernate that it's almost always best to start with a working example, so I suggest you get the FirstAutomappedProject sample project that is part of the FNH source. This will give you all the pieces you need.
Probably easiest to download the zip file (button on the upper left) which includes all the FNH source code, and look in the "src" folder for the examples.