All I want is a simple script to update some db tables.
My first try was with create-script. These scripts seem not be able to load domain classes. Then I found people saying, you have to create a command.
But in order to create a command you need to create a plugin.
This seems not very straight forward to a have a simple dbupdate script.
Can somebody enlighten me on this.
Thanks
Torsten
Alright! Looks like it is more related to how perform certain db related operations which are not straight forward db-migrations.
Though there could be enormous choices around it, I would like to discuss what could commonly be used:
Groovy Shell: You could create a straight forward groovy shell for your grails project and there run a script you created. No matter it is for some data update or some migration or just a report etc.
The basic idea is to have a command line available to run scripts that perform certain task. This link should help more.
DBMigration: Though in comment you already said it's not a dbmigration,I think your definition of dbmigration is restricted to schema related operations only. That's not true! DBmigration includes schema + CRUD(including a complicated version with join etc as well). We don't prefer crud operations as part of dbmigration as it could be achieved during bootstrap time or using a service method or even some external query or tool.
Like you perform any operation using your application, you could perform this action too. Suppose, you have to perform some updates and inserts in a table. Simply create a service and a controller which access this service to perform desired results. I know this makes least sense, but overall idea is to have a code which could perform desired action.
Well! I would suggest go ahead with first option and create a new shell project pointing to same database. Perform the action there.
Related
I'm interested in uploading a script (file) via my Rails application and then being able to execute this on demand.
I imagine the first step here is to handle the file upload such that I a Model which I can reference the file like Model.script. This makes sense to me.
And then from here, my plan is to expose a route/controller method which would execute this script, but I'm not sure how to handle the actual execution inside this method. For example if I had
class Model
def run_script
# logic to run self.script
end
end
How would I execute the associated file/code given that it is a Ruby file? Note that the script does not need to run in the context of the Rails application, it just needs to run.
You can use eval, which will run a Ruby script, but be very, very, careful!
For a detailed explanation see "Code is data, data is code".
Example:
eval(#model_instance.script)
eval is very dangerous. If you give a user the ability to upload and run an unchecked script, it may create a huge problem. For example, someone can upload a script like this:
User.delete_all
This will delete all users from the users table using a SQL query without invoking any Active Record callbacks.
You can use Ruby's taint method to add some additional safety, but it is not 100% foolproof.
For a detailed example, see "Locking Ruby in the Safe".
I have been looking for very basic keyword driven test..i do not understand well how you can separate the test specifically from application so its reusable. In my understanding, the QTP commands like "navigate" are keywords. But how to create my own independent ones? I would be very grateful for example of how to do that. I found either too complex or just theoretical ones.
Thank you very much
In QTP jargon a keyword is a combination of a test object and method (see the available keywords pane).
Keyword driven testing is used to mean creating a test without recording. You can create test objects in one of the following methods and then construct a test from these test objects.
Descriptive programming
Manually create test objects in the object repository (using the create new command)
Using navigate and learn
Record and discard the script
Import from XML
Example of a test.
Go to a web store. Search for a product. Login. Buy. Logout.
(The test is already broken down to keywords)
The simplest approach.
Simply write a list of operations for the corresponding objects. E.g. a simplified variant:
Browser.Open(WebStoreURL)
Browser.Sync
Browser.Page.WebEdit(SearchBoxName).Type "something I want"
' then login, buy, logout using the same approach
' add verification points where needed
In the end you have quite a long script.
If you need to write another script that tests a similar case, you need to repeat most of the actions above.
Another approach.
To avoid duplication, you can, for example, create such functions/actions: Login, Logout, Search(product_name), etc. And then create scripts using these actions/functions, i.e. keywords:
Login
Search "something I want"
Buy
Logout
It is an example of a keyword driven approach. It works on a higher level of abstraction then QTP commands.
The approach is not limited to using QTP functions. Keywords can be implemented as words in an Excel file.
I don't know about overloading of keywords. But when i was writing test cases in QTP for automation. I used configurable navigation paths in the prop or config file n all i needed to do was call a generic function which took source n destination n using those prop files navigate to the proper location.
I sure hope this is an ok question to ask here. I realize it isn't a specific programming Q, but hopefully it does have an answer.
I've been trying to learn Symfony (PHP framework) and I've gone through the Jobeet tutorial as well as read through the massive "Book". So I sit here about to begin my first project and amazingly find myself absolutely stuck on what to do. I realized that after reading all that... that I didn't "get" what the overall flow was. I'm asking this here because of the WIKI style so this can be adopted by experienced symfony users and melded into a final document that myself and other symfonewbies can use.
I'm beginning this from the point of view of a Windows user with a local server setup and the folder(s) containing php and symfony executables have been added to my PATH environment variable. I'm also using the assumption that Doctrine is being used rather than Propel as it has been stated in the docs that the default setup will be Doctrine going forward.
Create a folder for your project. Open a command line (in Windows, Start -> cmd.exe) and use the generate:project command to make the skeleton.
I'm really already lost here. From the Jobeet tutorial it seems to suggest the next step is creating your database in schema.yml and running doctrine:build-all? Or does generate:app and generate:module etc come first?
and so-on.
I'd appreciate any symfony pros out there contributing. Thanks.
Come up with a concept
First of all think of an interesting project that you would like to build. The default for this kind of project is usually a blog, but if that does not float your boat, how about something like a twitter clone or a reddit clone?
Build your model
In Symfony, the thing to do now is build your model. Create it in either a schema.YML file or in a graphical product like DB Designer, MySQL Workbench etc.
You need to add the tables, columns and foreign keys so that Propel can build you an interesting model to play with.
Let symfony build your apps
Now get on to the Symfony command line and create a couple of apps. A frontend, for the web and a backend to manage the site as an administrator.
Now let Symfony generate your model based on your schema. The lib/model folder should now have a load of files, filled with some useful functions based on your model.
For your backend app, generate a CRUD system with the admin generator and customise it with the yml file provided. Follow the myfirstapp tutorial for some interesting additions for the CRUD site.
Go in and edit your freshly built site!
For the Front end, create a module for each of the major parts of your site. These may include users, articles, tags, comments, stories, links, votes etc etc. Once you have some modules set up, the real fun starts. Create some functions in your actions file (such as list, show, delete, update) and create corresponding template files to display the results of the action.
Each action you create is automatically mapped to a corresponding URL.
http://yoursite/module/action
Hope this gives you some inspiration!
Follow the process in the jobeet tutorial - you've said that it suggests creating/defining the model is the next step, its what I always do.
Then create some fixtures, then go generating applications/modules etc. Once you reach this point, there's less need to stick to the order jobeet does things, but its still a good reference.
I am trying to build a script to automate the update process for symfony projects. E.g. apply any patches from one revision to another including any possible model updates and new fixtures without re-loading the entire database.
I have completed most of it, but I have been unable to find a way to generate an SQL file containing the INSERT statements that get executed by propel load data when it inserts the fixture.
I know that I could dump the database to get the info, but that's not the point and that wouldn't work in my case because I'd need an empty db that has no other data on it.
So in short, my question is: Is there a way to take a fixture YML and generate the SQL inserts necessary?
I know this could be done by processing the yml and building the logic, but the build process it does it somewhere and there's no reason to write that again..
Any help would be much appreciated.
Perhaps I did not understand your question correctly, but couldn't you just call the task that loads the fixtures into the db, or alternatively write code that calls sfPropelData::loadData() (I'm assuming Propel here).
$loader = new sfPropelData();
$loader->loadData(sfConfig::get('sf_data_dir').'/fixtures');
Even sfPropelData and its parent sfData do not generate sql code when loading fixtures, but rather do it using the ORM (as can be seen in sfPropelData::loadDataFromArray().
If you explained your problem more, and why this solution isn't enough, I may be able to help.
The rails books and web pages I've been following have all stuck to very simple projects for the sake of providing complete examples. I'm moving away from the small project app and into a realm of non-browser clients and need to decide where to put code that is shared by all involved parties.
The non-browser client is a script that runs on any machine which can connect to the database. Browser clients write commands into the database, which the script examines and decides what to do. Upon completion, the script then writes its result back. The script is not started by the RoR server, but has access to its directory structure.
Where would be the best place for shared code to live, and how would the RoR loader handle it? The code in question doesn't really belong in a model, otherwise I'd drop it in there and be done with it.
I'd put the shared code in the Rails project's /lib directory and consider making it a custom Rake task.
It really depends on how much you use this shared code. If you use it everywhere, then throw it in the lib folder (as has already been stated here). If you are only using it in a few places, you might want to consider making a plugin out of it and loading it only in the places that use it. It's nice to only load what you need (one of the reasons I'm loving merb).