(not logged in) | Login

Chinook Demo / Part 1.3 - App & Environment Setup

1.2 - Agenda Back to List 2.1 - Out of the Box Basics

  Download video file:  chinook_part_1.3_app_setup.mp4



Commands
cmd_history.sh#L82-L155
Commits
3ae1821  –  first commit - freshly created Catalyst app
734d852  –  setup chinook SQLite database
beb8d0a  –  Created DBIC schema/model "DB"
01_prepared_app

Try it yourself:

# install/upgrade RapidApp:
cpanm RapidApp

# clone the repo:
git clone http://github.com/IntelliTree/RA-ChinookDemo.git
cd RA-ChinookDemo/

# checkout the code as of the end of this video -
#  ("Part 1.3 - App & Environment Setup"):
git checkout 01_prepared_app

# start the test server:
script/ra_chinookdemo_server.pl

Video Transcript

So, first things first, we need to download and install the latest RapidApp from CPAN.

As you can see, I already have RapidApp on my system, but if I didn't, it would have been automatically installed, along with all its dependencies, including Catalyst.

If you don't have cpanm, you need to install cpanminus. Cpanminus is a handy tool for installing CPAN packages with dependencies without all the fuss and setup required for the traditional cpan client.

Next, we need to create the new Catalyst application using the helper script provided by Catalyst. The app could be named anything, but I'm going to call it RA::ChinookDemo, as you can already see from the name of the Git repository, which we'll setup next.

The catalyst.pl helper script has now created a skeleton of base files and directories which will be working in moving forward.

Now I'm going to setup the actual git repository and tracking mechanisms I already described for the purposes of the demo.

First, Initialize a fresh repo, and then link it to Github -- this is the actual command where this happened.

I'm going to setup a shortcut command to automate recording the changes as we go, so we can use 'Commit' with a capital C to:

  • Append the latest command history to cmd_history.sh
  • Reformat multiline commands, which I'll explain in a second
  • Add all changes to the git index
  • and commit those changes with a commit message

RestoreHistNewlines is itself an alias which I'll create now.

This is just for formatting of the history file, so that commands we split up into multiple lines using backslashes will look the same instead of being mushed into one line.

We're just using sed to do some string processing. You don't need to understand this unless you're interested. The only reason it's being shown is because in this demo, everything is, and it is a helpful shortcut you might want to use for your own projects.

But, the only thing that matters for the purposes of the demo is that we can now record changes as we go with a single command, which we'll be doing throughout the rest of the demo:

Now we need to download the actual Chinook database, from their website.

Chinook is available in multiple formats, and DBIC supports multiple formats, but we'll be using SQLite for this demo.

I downloaded and extracted this zip file into the parent directory of our app, and I'll copy into our working directory now.

There are several different formats available within in the zip file, each containing both the DDL, or schema, and the sample data.

We're going to use the text-based SQL version, with auto-increments.

As you can see, this file is about 1.7 megs.

Now, I'm going to use it to create a new SQLite database as chinook.db in the current directory. This process takes a little while, about 10 minutes. I'll run it through time to show how long it actually takes.

Note that this is error is safe to ignore; it's just caused by the Unicode BOM, or byte order mark, that the Chinook people have put at the start of the sql file. I could have removed it, but it doesn't hurt anything.

Now let's fast-forward to the future.

As you can see, command finished and ended up taking just over 8 minutes.

Let's go ahead and commit our progress.

Now we're going to create a Catalyst DBIC Schema Model for the new database using the helper script. This is still standard Catalyst. Under the hood this uses DBIC's Schema::Loader to automatically generate schema and result classes based on the database we just created.

  • We're creating a new model called 'DB', which is just the name I picked, it could be anything
  • based on DBIC::Schema, which tells Catalyst which helper to use
  • using this for the DBIC schema namespace
  • And now we'll set some Schema::Loader options, creating the result classes one time, statically, and also turning off POD generation in the created files
  • Now comes the DSN string, which we're pointing at our SQLite database file
  • And finally, we'll set some SQLite-specific connect_info options, such as enabling Unicode
  • and turning on foreign key constraints, which are standard, but not on by default in SQLite
  • and finally, setting quote_names, which has to do with how keywords are quoted in the SQL DBIC generates, and is required for RapidApp

For more info on this command and the available options, see the DBIC::Schema helper docs on CPAN

Now we'll commit the changes, which shows the files that were just created.

These include the DBIC Schema and 11 result classes for each of the tables in the Chinook database, and the Catalyst Model, which links to them.

We've now prepared a fresh Catalyst application environment. It doesn't do anything yet, but has the basic plumbing for access to the database that will serve as our launch point.

Let's make another commit with a tag so its easy to jump back to this spot, ... and push to Github.

In the next section we'll enable RapidApp and the RapidDbic plugin, and start playing with and configuring its out-of-the-box interfaces.


For support, or to learn more about the RapidApp project, please visit the #rapidapp IRC channel on irc.perl.org