.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "DBSchema 3pm" .TH DBSchema 3pm "2015-05-07" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::DBSchema \- Database\-independent schema objects .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use DBIx::DBSchema; \& \& $schema = new DBIx::DBSchema @dbix_dbschema_table_objects; \& $schema = new_odbc DBIx::DBSchema $dbh; \& $schema = new_odbc DBIx::DBSchema $dsn, $user, $pass; \& $schema = new_native DBIx::DBSchema $dbh; \& $schema = new_native DBIx::DBSchema $dsn, $user, $pass; \& \& $schema\->save("filename"); \& $schema = load DBIx::DBSchema "filename" or die $DBIx::DBSchema::errstr; \& \& $schema\->addtable($dbix_dbschema_table_object); \& \& @table_names = $schema\->tables; \& \& $DBIx_DBSchema_table_object = $schema\->table("table_name"); \& \& @sql = $schema\->sql($dbh); \& @sql = $schema\->sql($dsn, $username, $password); \& @sql = $schema\->sql($dsn); #doesn\*(Aqt connect to database \- less reliable \& \& $perl_code = $schema\->pretty_print; \& %hash = eval $perl_code; \& use DBI qw(:sql_types); $schema = pretty_read DBIx::DBSchema \e%hash; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" DBIx::DBSchema objects are collections of DBIx::DBSchema::Table objects and represent a database schema. .PP This module implements an OO-interface to database schemas. Using this module, you can create a database schema with an \s-1OO\s0 Perl interface. You can read the schema from an existing database. You can save the schema to disk and restore it in a different process. You can write \s-1SQL CREATE\s0 statements statements for different databases from a single source. You can transform one schema to another, adding any necessary new columns, tables, indices and foreign keys. .PP Currently supported databases are MySQL, PostgreSQL and SQLite. Sybase and Oracle drivers are partially implemented. DBIx::DBSchema will attempt to use generic \s-1SQL\s0 syntax for other databases. Assistance adding support for other databases is welcomed. See DBIx::DBSchema::DBD, \*(L"Driver Writer's Guide and Base Class\*(R". .SH "METHODS" .IX Header "METHODS" .IP "new \s-1TABLE_OBJECT, TABLE_OBJECT, ...\s0" 4 .IX Item "new TABLE_OBJECT, TABLE_OBJECT, ..." Creates a new DBIx::DBSchema object. .IP "new_odbc \s-1DATABASE_HANDLE\s0 | \s-1DATA_SOURCE USERNAME PASSWORD\s0 [ \s-1ATTR \s0]" 4 .IX Item "new_odbc DATABASE_HANDLE | DATA_SOURCE USERNAME PASSWORD [ ATTR ]" Creates a new DBIx::DBSchema object from an existing data source, which can be specified by passing an open \s-1DBI\s0 database handle, or by passing the \s-1DBI\s0 data source name, username, and password. This uses the experimental \s-1DBI\s0 type_info method to create a schema with standard (\s-1ODBC\s0) \s-1SQL\s0 column types that most closely correspond to any non-portable column types. Use this to import a schema that you wish to use with many different database engines. Although primary key and (unique) index information will only be read from databases with DBIx::DBSchema::DBD drivers (currently MySQL and PostgreSQL), import of column names and attributes *should* work for any database. Note that this method only uses \*(L"\s-1ODBC\*(R"\s0 column types; it does not require or use an \s-1ODBC\s0 driver. .IP "new_native \s-1DATABASE_HANDLE\s0 | \s-1DATA_SOURCE USERNAME PASSWORD\s0 [ \s-1ATTR \s0]" 4 .IX Item "new_native DATABASE_HANDLE | DATA_SOURCE USERNAME PASSWORD [ ATTR ]" Creates a new DBIx::DBSchema object from an existing data source, which can be specified by passing an open \s-1DBI\s0 database handle, or by passing the \s-1DBI\s0 data source name, username and password. This uses database-native methods to read the schema, and will preserve any non-portable column types. The method is only available if there is a DBIx::DBSchema::DBD for the corresponding database engine (currently, MySQL and PostgreSQL). .IP "load \s-1FILENAME\s0" 4 .IX Item "load FILENAME" Loads a DBIx::DBSchema object from a file. If there is an error, returns false and puts an error message in \f(CW$DBIx::DBSchema::errstr\fR; .IP "save \s-1FILENAME\s0" 4 .IX Item "save FILENAME" Saves a DBIx::DBSchema object to a file. .IP "addtable \s-1TABLE_OBJECT\s0" 4 .IX Item "addtable TABLE_OBJECT" Adds the given DBIx::DBSchema::Table object to this DBIx::DBSchema. .IP "tables" 4 .IX Item "tables" Returns a list of the names of all tables. .IP "table \s-1TABLENAME\s0" 4 .IX Item "table TABLENAME" Returns the specified DBIx::DBSchema::Table object. .IP "sql [ \s-1DATABASE_HANDLE\s0 | \s-1DATA_SOURCE\s0 [ \s-1USERNAME PASSWORD\s0 [ \s-1ATTR \s0] ] ]" 4 .IX Item "sql [ DATABASE_HANDLE | DATA_SOURCE [ USERNAME PASSWORD [ ATTR ] ] ]" Returns a list of \s-1SQL\s0 `\s-1CREATE\s0' statements for this schema. .Sp The data source can be specified by passing an open \s-1DBI\s0 database handle, or by passing the \s-1DBI\s0 data source name, username and password. .Sp Although the username and password are optional, it is best to call this method with a database handle or data source including a valid username and password \- a \s-1DBI\s0 connection will be opened and used to check the database version as well as for more reliable quoting and type mapping. Note that the database connection will be used passively, \fBnot\fR to actually run the \s-1CREATE\s0 statements. .Sp If passed a \s-1DBI\s0 data source (or handle) such as `DBI:mysql:database' or `DBI:Pg:dbname=database', will use syntax specific to that database engine. Currently supported databases are MySQL and PostgreSQL. .Sp If not passed a data source (or handle), or if there is no driver for the specified database, will attempt to use generic \s-1SQL\s0 syntax. .IP "sql_update_schema [ \s-1OPTIONS_HASHREF, \s0] \s-1PROTOTYPE_SCHEMA\s0 [ \s-1DATABASE_HANDLE\s0 | \s-1DATA_SOURCE\s0 [ \s-1USERNAME PASSWORD\s0 [ \s-1ATTR \s0] ] ]" 4 .IX Item "sql_update_schema [ OPTIONS_HASHREF, ] PROTOTYPE_SCHEMA [ DATABASE_HANDLE | DATA_SOURCE [ USERNAME PASSWORD [ ATTR ] ] ]" Returns a list of \s-1SQL\s0 statements to update this schema so that it is idential to the provided prototype schema, also a DBIx::DBSchema object. .Sp Right now this method knows how to add new tables and alter existing tables, including indices. If specifically requested by passing an options hashref with \fBdrop_tables\fR set true before all other arguments, it will also drop tables. .Sp See \*(L"sql_alter_table\*(R" in DBIx::DBSchema::Table, \&\*(L"sql_add_column\*(R" in DBIx::DBSchema::Column and \&\*(L"sql_alter_column\*(R" in DBIx::DBSchema::Column for additional specifics and limitations. .Sp The data source can be specified by passing an open \s-1DBI\s0 database handle, or by passing the \s-1DBI\s0 data source name, username and password. .Sp Although the username and password are optional, it is best to call this method with a database handle or data source including a valid username and password \- a \s-1DBI\s0 connection will be opened and used to check the database version as well as for more reliable quoting and type mapping. Note that the database connection will be used passively, \fBnot\fR to actually run the \s-1CREATE\s0 statements. .Sp If passed a \s-1DBI\s0 data source (or handle) such as `DBI:mysql:database' or `DBI:Pg:dbname=database', will use syntax specific to that database engine. Currently supported databases are MySQL and PostgreSQL. .Sp If not passed a data source (or handle), or if there is no driver for the specified database, will attempt to use generic \s-1SQL\s0 syntax. .IP "update_schema [ \s-1OPTIONS_HASHREF, \s0] \s-1PROTOTYPE_SCHEMA, DATABASE_HANDLE\s0 | \s-1DATA_SOURCE\s0 [ \s-1USERNAME PASSWORD\s0 [ \s-1ATTR \s0] ]" 4 .IX Item "update_schema [ OPTIONS_HASHREF, ] PROTOTYPE_SCHEMA, DATABASE_HANDLE | DATA_SOURCE [ USERNAME PASSWORD [ ATTR ] ]" Same as sql_update_schema, except actually runs the \s-1SQL\s0 commands to update the schema. Throws a fatal error if any statement fails. .IP "pretty_print" 4 .IX Item "pretty_print" Returns the data in this schema as Perl source, suitable for assigning to a hash. .IP "pretty_read \s-1HASHREF\s0" 4 .IX Item "pretty_read HASHREF" This method is \fBnot\fR recommended. If you need to load and save your schema to a file, see the \*(L"load\*(R" and \*(L"save\*(R" methods. .Sp Creates a schema as specified by a data structure such as that created by \&\fBpretty_print\fR method. .SH "AUTHORS" .IX Header "AUTHORS" Ivan Kohler .PP Charles Shapiro and Mitchell Friedman contributed the start of a Sybase driver. .PP Daniel Hanks contributed the Oracle driver. .PP Jesse Vincent contributed the SQLite driver and fixes to quiet down internal usage of the old \s-1API.\s0 .PP Slaven Rezic contributed column and table dropping, Pg bugfixes and more. .SH "CONTRIBUTIONS" .IX Header "CONTRIBUTIONS" Contributions are welcome! I'm especially keen on any interest in the top items/projects below under \s-1BUGS.\s0 .SH "REPOSITORY" .IX Header "REPOSITORY" The code is available from our public git repository: .PP .Vb 1 \& git clone git://git.freeside.biz/DBIx\-DBSchema.git .Ve .PP Or on the web: .PP .Vb 3 \& http://freeside.biz/gitweb/?p=DBIx\-DBSchema.git \& Or: \& http://freeside.biz/gitlist/DBIx\-DBSchema.git .Ve .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2000\-2007 Ivan Kohler Copyright (c) 2000 Mail Abuse Prevention System \s-1LLC\s0 Copyright (c) 2007\-2015 Freeside Internet Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "BUGS AND TODO" .IX Header "BUGS AND TODO" Multiple primary keys are not yet supported. .PP Foreign keys: need to support dropping, \s-1NOT VALID,\s0 reverse engineering w/mysql .PP Need to port and test with additional databases .PP Each DBIx::DBSchema object should have a name which corresponds to its name within the \s-1SQL\s0 database engine (\s-1DBI\s0 data source). .PP Need to support \*(L"using\*(R" index attribute in pretty_read and in reverse engineering .PP sql \s-1CREATE TABLE\s0 output should convert integers (i.e. use \s-1DBI\s0 qw(:sql_types);) to local types using \s-1DBI\-\s0>type_info plus a hash to fudge things .SS "\s-1PRETTY_ BUGS\s0" .IX Subsection "PRETTY_ BUGS" pretty_print is actually pretty ugly. .PP pretty_print isn't so good about quoting values... save/load is a much better alternative to using pretty_print/pretty_read .PP pretty_read is pretty ugly too. .PP pretty_read should *not* create and pass in old-style unique/index indices when nothing is given in the read. .PP Perhaps pretty_read should eval column types so that we can use \s-1DBI\s0 qw(:sql_types) here instead of externally. .PP perhaps we should just get rid of pretty_read entirely. pretty_print is useful for debugging, but pretty_read is pretty bunk. .SH "SEE ALSO" .IX Header "SEE ALSO" DBIx::DBSchema::Table, DBIx::DBSchema::Index, DBIx::DBSchema::Column, DBIx::DBSchema::DBD, DBIx::DBSchema::DBD::mysql, DBIx::DBSchema::DBD::Pg, FS::Record, \&\s-1DBI\s0