Archive for March, 2009

PyMigrate 1.0 Stable Release

March 7th, 2009 by ScottK | No Comments | Filed in PyMigrate

I’ve released the first stable version of PyMigrate today. This release actually detaches all the database API’s to SqlAlchemy. So you will need SqlAlchemy and the associated eggs for your database per SqlAlchemy.

You can find the downloadable versions here online casinoPyMigrate Downloads and the svn repo backgammon free casino money free craps game play free black jack craps video poker strategy play black jack online how to win video poker casino game online uk best casino online casino secure online gambling jackpot casino online casino black jack learn to play craps how to win at video poker craps online blackjack casino game online casino betting free on line video poker casino games no download casino online gambling casino play free casino slots video poker machine bonus video poker free on line slots double bonus video poker free video poker games free casinos roulette online craps rules free on line casino rules of craps online casino free money blackjack 21 internet casino how to play craps free casino game download fortunelounge online casino free casino download free casino card game free roulette game free casino play no deposit free money casino internet casino online here. The supported database API’s (for now) are:

Mysql
Sqlite
Oracle
DB2
Postgres
Oracle
MSSQL

While SqlAlchemy may lack some things, such as dropping an index, the PyMigrate app accomplishes this through a straight sql statement. Granted some of the databases do not support some actions, such as rename colum in Sqlite.

PyMigrate helps all of us quickly change up/down our databases, but I know from a dba stand point that we need “total” control of a few things. So I made the Sql block read multiple lines, instead of one line. That gives you absolute control of your database migration as you need, and still allows you to revert it as needed.

So PyMigrate offers common modifications to tables/indexes/colums, etc. Using the sql: block will the most control you can have.

I’m happy to release this version and will soon be adding more database API’s. Feel free to comment!

CakePHP RESTFul Resources, Not There Yet.

March 5th, 2009 by ScottK | 3 Comments | Filed in cakePHP

Now that CakePHP 1.2 is a stable version I’ve picked back up on it. When I looked at it as a release candidate, and after they announced RESTFul routing, I specifically looked at the RESTful implementation. I’m looking at it again and find it’s still not there.

Looking at the router.php file for the Router::mapResources :

var $__resourceMap = array(
array('action' => 'index', 'method' => 'GET',  'id' => false),
array('action' => 'view',  'method' => 'GET',  'id' => true),
array('action' => 'add',  'method' => 'POST',  'id' => false),
array('action' => 'edit',  'method' => 'PUT',  'id' => true),
array('action' => 'delete',  'method' => 'DELETE', 'id' => true),
array('action' => 'edit',  'method' => 'POST', 'id' => true)
);

The first thing pops out and smells is the double entry for the edit action. This clearly indicates that I’ll need to put in conditional logic to either present the edit view or save a posted edit form. One of those edit methods needs to be changed to an update action to remove the edit conditionals.

There are actions missing from the mapResources as well. Where’s the new(create) action? This presents a view with the fields for creating a new record of whatever. Certainly submitting the form would POST to the add action.

As it stands and as advertised the mapResources does work. /posts calls the index action. /posts/1 calls the view action. So how can the two missing actions (update / new) be added easily?

The original config/routes.php file would look like this:

Router::mapResources('posts');

Just add two lines above the mapResources:

Router::connect("/:controller/:id", array("action" => "update", "[method]" => "PUT"),array('pass' => array('id'));
Router::connect("/:controller/new", array("action" => "create", "[method]" => "GET"));

//Original
Router::mapResources('posts');

As long as those two lines are above any mapped resources they will all act the same. So:

Router::connect("/:controller/:id", array("action" => "update", "[method]" => "PUT"),array('pass' => array('id'));
Router::connect("/:controller/new", array("action" => "create", "[method]" => "GET"));
Router::mapResources('posts')
Router::mapResources('users');

Will apply the new update and create routing for both posts and users.

There is one other thing that is bugging me about the cakePHP RESTFul implementation. The PUT/POST method to call an edit view. I want to be able to call posts/1/edit with a GET to display the edit view. So with one more line of code in the routes.php file.

Router::connect("/:controller/:id/edit", array("action" => "edit", "[method]" => "GET"),array('pass' => array('id'));
Router::connect("/:controller/:id", array("action" => "update", "[method]" => "PUT"),array('pass' => array('id'));
Router::connect("/:controller/new", array("action" => "create", "[method]" => "GET"));
Router::mapResources('posts')
Router::mapResources('users');

Now we have RESTFul routing for these routes!

URL Method Action
/posts GET index()
/posts POST add()
/posts/new GET create()
/posts/1 GET view($id)
/posts/1 PUT update($id)
/posts/1/edit GET edit($id)
/posts/1 DELETE delete($id)
/users GET index()
/users POST add()
/users/new GET create()
/users/1 GET view($id)
/users/1 PUT update()
/users/1/edit GET edit($id)
/users/1 DELETE delete($id)

Tags: , , ,