Alzabo::Create::Schema - Schema objects for schema creation
use Alzabo::Create::Schema;
This class represnets the whole schema, and contains table objects.
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.
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
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.
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.
AlzaboException - Table already exists in the table. See Alzabo::Create::Table docs for other exceptions
add_table
-- 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.
move_table
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.
AlzaboException - Table doesn't exist in schema.
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.
AlzaboException - one of the tables passed in is not part of the schema. AlzaboException - both a 'before' and 'after' parameter were specified.
add_relation
-- 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
-- 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
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.
Dave Rolsky, <autarch@urth.org>
25 POD Errors
The following errors were encountered while parsing the POD:
Expected '=item *'
To install Alzabo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Alzabo
CPAN shell
perl -MCPAN -e shell install Alzabo
For more information on module installation, please visit the detailed CPAN module installation guide.