Search code examples
perldbix-classmojolicious

Mojolicious Deploying database schema


I am currently working through this tutorial on building a Mojolicious web app for a project. In the tutorial he talks about using this in a script to create a database schema.

my $schema = Moblo::Schema->connect('dbi:SQLite:moblo.db');
$schema->deploy();

and I have tried running perl -e '...', putting it in different files and everything else I can think of, but with no success.

Here is my code on GitHub.

I am pretty lost on how to get this thing to create the schema so any help would be appreciated.


Solution

  • It's not clear why the author wrote only a part of the deployment script. Perhaps he thought it was obvious that you needed use Moblo::Schema in there. Perhaps he was right.

    This program works fine. Call it anything you like—say deploy.pl—and put it in the moblo/lib directory.

    use strict;
    use warnings;
    
    use Moblo::Schema;
    
    my $schema = Moblo::Schema->connect('dbi:SQLite:moblo.db');
    $schema->deploy();