Can DBIx::Class be used to create tables?
Asked Answered
E

2

9

I do not think I understand the scope of DBIx::Class
Do I have to manually create a database with regular SQL first, then use the schemaloader (or manually code the schema/resultsets)?
Or is there a way to tell DBIx::Class to go ahead and create the tables from a manually coded schema and resultset?
I ask b/c if I need to create the database via SQL CREATE TABLE statement, I have the column essentially duplicated in the ResultSet code, OR I need to rely on schemaloader which I assume is inefficient and inappropriate for production.

Earthshaker answered 9/10, 2012 at 9:12 Comment(0)
D
14

You can deploy() your schema:

my $schema = MyApp::Schema->connect(
          $dsn,
          $user,
          $password,
        );
$schema->deploy( { add_drop_table => 1 } );

Of course, the above will drop your existing tables :)

Delao answered 9/10, 2012 at 9:18 Comment(0)
L
10

You can go either route. You can create a schema and get DBIx::Class to analyse it, or you can get DBIx::Class to build the schema to you.

The former does not have to be inefficient for production, since you can get DBIx::Class to save the generated code so that it doesn't have to do the analysis every run.

Linotype answered 9/10, 2012 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.