The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Alzabo::Create::Schema - Schema objects for schema creation

SYNOPSIS

  use Alzabo::Create::Schema;

DESCRIPTION

This class represnets the whole schema, and contains table objects.

METHODS

  • new

    Takes the following parameters:

  • -- name => $name

  • -- rules => $rules_subclass

  • -- driver => $driver_subclass

    The values given to rules and driver should be the identifying piece of the subclass. For example, to use the MySQL driver you'd give the string 'MySQL' (which identifies the class Alzabo::Driver::MySQL).

    Exceptions:

     AlzaboException - no name provided.
  • load_from_file($name)

    Returns a schema object previously saved to disk based on the name given.

    Exceptions:

     AlzaboException - No saved schema of the given name.
     FileSystemException - Can't open, close or stat a file.
     EvalException - Unable to evaluate the contents of a file.
  • reverse_engineer

    Takes the following parameters:

  • -- name => $name

  • -- rules => $rules_subclass

  • -- driver => $driver_subclass

    See the new method documentation for an explanation of the 'rules' and 'driver' parameters.

  • -- user => $user (optional)

    User name to use when connecting to database.

  • -- password => $password (optional)

    Password to use when connecting to database.

    Attempts to connect to a database and instantiate a new schema object based on information on a given database. The returned object will have its instantiated value set to true so that subsequent changes will lead to SQL diffs, as opposed to SQL to create the database from scratch.

  • set_name ($name)

    Change the schema name. Since the schemas are saved on disk based on the name, this deletes the files under the old name. Call save_to_file immediately afterwards if you want to make sure you have a copy of the schema saved.

    Exceptions:

     AlzaboRDBMSRulesException - invalid schema name.
  • make_table (see below)

    This method makes a new table and adds it to the schema, the parameters given are passed directly to the Alzabo::Create::Table->new method. In addition, the schema fills in the schema parameter for the table.

    Exceptions:

     AlzaboException - Table already exists in the table.
    
     See Alzabo::Create::Table docs for other exceptions
  • add_table

    Takes the following parameters:

  • -- table => Alzabo::Create::Table object

  • -- after => Alzabo::Create::Table object (optional)

    Add a table to the schema. If the 'after' parameter is given then the move_table method will be called to move the new table to the appropriate position.

    Exceptions:

     AlzaboException - Table already exists in schema.
  • delete_table( Alzabo::Create::Table object )

    Removes the given table from the schema. Will also delete all foreign keys in other tables that it can find a link to.

    Exceptions:

    AlzaboException - Table doesn't exist in schema.

  • move_table

    Takes the following parameters:

  • -- table => Alzabo::Create::Table object

    The table to move.

    and either ...

  • -- before => Alzabo::Create::Table object

    Move the table before this table

    ... or ...

  • -- after => Alzabo::Create::Table object

    Move the table after this table.

    Exceptions:

     AlzaboException - one of the tables passed in is not part of the
     schema.
     AlzaboException - both a 'before' and 'after' parameter were
     specified.
  • add_relation

    Takes the following parameters:

  • -- table_from => Alzabo::Create::Table object

  • -- table_to => Alzabo::Create::Table object

  • -- column_from => Alzabo::Create::Column object (optional)

  • -- column_to => Alzabo::Create::Column object (optional)

  • -- min_max_from => (see below)

  • -- min_max_to => (see below)

    The two min_max attributes both take the same kind of argument, an array reference two scalars long.

    The first of these scalars can be the value '0' or '1' while the second can be '1' or 'n'.

    Creates a relationship between two tables. This involves creating Alzabo::Create::ForeignKey objects in both tables. If the 'column_from' and 'column_to' parameters are not specified then the schema object attempts to calculate the proper values for these attributes.

    If both the 'min_max_from' and 'min_max_to' attributes are 0 or 1 to 'n' then a new table will be created to link the two tables together. This table will contain the primary keys of both the tables passed into this function. It will contain foreign keys to both of these tables as well and these tables will be linked to this new table.

  • instantiated

    Returns the value of the schema's instantiated attribute. It is true if the schema has been created in a RDBMS backend, otherwise false.

  • set_instantiated ($bool)

    Set the schema's instantiated attribute as true or false.

  • rules

    Returns the schema's Alzabo::RDBMSRules object.

  • create

    Takes the following parameters:

  • -- host => $host

  • -- user => $user

  • -- password => $user

    These three are all passed the schema's Alzabo::Driver object to connect to the database.

    This method causes the schema to connect to the RDBMS, create a new database if necessary, and then execute whatever SQL is necessary to make the database match the schema.

  • make_sql

    Returns an array containing the SQL statements necessary to either create the database from scratch or update the database to match the schema object.

  • drop

    Takes the following parameters:

  • -- host => $host

  • -- user => $user

  • -- password => $user

    These three are all passed the schema's Alzabo::Driver object to connect to the database.

    Drops the database/schema from the RDBMS. It does not delete the Alzabo files from disk. To do this, call the delete method.

  • delete

    Removes the schema object from disk. It does not delete the database from the RDBMS. To do this you must call the drop method first.

  • save_to_file

    Saves the schema to a file on disk. It also saves a version of the schema that has been re-blessed into the Alzabo::Runtime::* classes with the creation specific attributes removed.

AUTHOR

Dave Rolsky, <autarch@urth.org>

25 POD Errors

The following errors were encountered while parsing the POD:

Around line 897:

Expected '=item *'

Around line 899:

Expected '=item *'

Around line 901:

Expected '=item *'

Around line 926:

Expected '=item *'

Around line 928:

Expected '=item *'

Around line 930:

Expected '=item *'

Around line 935:

Expected '=item *'

Around line 939:

Expected '=item *'

Around line 977:

Expected '=item *'

Around line 979:

Expected '=item *'

Around line 1002:

Expected '=item *'

Around line 1008:

Expected '=item *'

Around line 1014:

Expected '=item *'

Around line 1029:

Expected '=item *'

Around line 1031:

Expected '=item *'

Around line 1033:

Expected '=item *'

Around line 1035:

Expected '=item *'

Around line 1037:

Expected '=item *'

Around line 1039:

Expected '=item *'

Around line 1076:

Expected '=item *'

Around line 1078:

Expected '=item *'

Around line 1080:

Expected '=item *'

Around line 1099:

Expected '=item *'

Around line 1101:

Expected '=item *'

Around line 1103:

Expected '=item *'