FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fo_libschema Class Reference

Class to handle database schema. More...

Collaboration diagram for fo_libschema:
Collaboration graph

Public Member Functions

 __construct (DbManager &$dbManager)
 
 setDriver (Driver &$dbDriver)
 
 applyOrEchoOnce ($sql, $stmt='')
 
 applySchema ($filename=NULL, $debug=false, $catalog='fossology', $migrateColumns=array())
 Make schema match $Filename. This is a single transaction. More...
 
 applySequences ()
 Add sequences to the database. More...
 
 applyClusters ()
 Add clusters. More...
 
 updateSequences ()
 Add sequences. More...
 
 applyTables ($inherits=false)
 Add tables/columns (dependent on sequences for default values) More...
 
 applyViews ()
 
 dropConstraints ()
 Delete constraints. More...
 
 dropIndexes ()
 
 applyIndexes ()
 
 applyConstraints ()
 
 dropViews ($catalog)
 Delete views. More...
 
 dropColumnsFromTable ($columns, $table)
 
 getCurrSchema ()
 Load the schema from the db into an array.
 
 addInheritedRelations ()
 
 addTables ()
 
 addViews ($viewowner)
 
 addSequences ($referencedSequencesInTableColumns)
 
 addConstraints ()
 
 addIndexes ()
 
 addFunctions ($schema)
 
 writeArrayEntries ($fout, $key, $value, $varname)
 
 exportSchema ($filename=NULL)
 Export the schema of the connected ($PG_CONN) database to a file in the format readable by GetSchema(). More...
 
 makeFunctions ()
 Create any required DB functions.
 
 applyInheritedRelations ()
 

Public Attributes

 $debug = false
 

Private Attributes

 $dbman
 
 $schema = array()
 
 $currSchema = array()
 

Detailed Description

Class to handle database schema.

Definition at line 28 of file libschema.php.

Constructor & Destructor Documentation

◆ __construct()

fo_libschema::__construct ( DbManager $dbManager)

Constructor for fo_libschema

Parameters
DbManager$dbManager

Definition at line 58 of file libschema.php.

Member Function Documentation

◆ addConstraints()

fo_libschema::addConstraints ( )

Add constraints to the current schema

Definition at line 715 of file libschema.php.

◆ addFunctions()

fo_libschema::addFunctions (   $schema)

Add functions to the given schema

Parameters
array$schemaSchema in which the functions are to be added
Returns
array Schema with functions under FUNCTION key

Definition at line 904 of file libschema.php.

◆ addIndexes()

fo_libschema::addIndexes ( )

Add indexes to the current schema

Definition at line 877 of file libschema.php.

◆ addInheritedRelations()

fo_libschema::addInheritedRelations ( )

Add inherited relations to the current schema.

Definition at line 570 of file libschema.php.

◆ addSequences()

fo_libschema::addSequences (   $referencedSequencesInTableColumns)

Add sequences to the current schema

Parameters
array$referencedSequencesInTableColumnsArray from addTables()

Definition at line 678 of file libschema.php.

◆ addTables()

fo_libschema::addTables ( )

Add tables to the current schema

Definition at line 589 of file libschema.php.

◆ addViews()

fo_libschema::addViews (   $viewowner)

Add views to the current schema

Parameters
string$viewownerOwner of the view

Definition at line 661 of file libschema.php.

◆ applyClusters()

fo_libschema::applyClusters ( )

Add clusters.

The function first checks if the cluster already exists or not. The cluster is only created only if it does not exists.

Definition at line 232 of file libschema.php.

◆ applyConstraints()

fo_libschema::applyConstraints ( )

Add constraints (dependent on columns, views, and indexes)

Definition at line 460 of file libschema.php.

◆ applyIndexes()

fo_libschema::applyIndexes ( )

Add indexes (dependent on columns)

Definition at line 426 of file libschema.php.

◆ applyInheritedRelations()

fo_libschema::applyInheritedRelations ( )

Apply inherits relations from schema on DB

Definition at line 1065 of file libschema.php.

◆ applyOrEchoOnce()

fo_libschema::applyOrEchoOnce (   $sql,
  $stmt = '' 
)

Apply or echo the SQL statement based on the debugging status.

Parameters
string$sqlStatement to be applied
string$stmtName of the statement (for caching)

Definition at line 78 of file libschema.php.

◆ applySchema()

fo_libschema::applySchema (   $filename = NULL,
  $debug = false,
  $catalog = 'fossology',
  $migrateColumns = array() 
)

Make schema match $Filename. This is a single transaction.

Parameters
string$filenameSchema file written by schema-export.php
bool$debugTurn on debugging (echo sql as it is being executed)
string$catalogOptional database name
array[]$migrateColumnsarray('tablename'=>array('col1','col2'),...) of columns which should not be deleted
Returns
false=success, on error return string with error message.

Definition at line 96 of file libschema.php.

◆ applySequences()

fo_libschema::applySequences ( )

Add sequences to the database.

The function first checks if the sequence already exists or not. The sequence is only created only if it does not exists.

Definition at line 209 of file libschema.php.

◆ applyTables()

fo_libschema::applyTables (   $inherits = false)

Add tables/columns (dependent on sequences for default values)

The function creates new tables in the database. The function also drops columns which are missing from schema and add new columns as well.

Definition at line 279 of file libschema.php.

◆ applyViews()

fo_libschema::applyViews ( )

Add views (dependent on columns)

Definition at line 347 of file libschema.php.

◆ dropColumnsFromTable()

fo_libschema::dropColumnsFromTable (   $columns,
  $table 
)

Delete columns from tables

Parameters
array$columnsName of columns to be dropped
string$tableName of the table

Definition at line 533 of file libschema.php.

◆ dropConstraints()

fo_libschema::dropConstraints ( )

Delete constraints.

Delete now, so they won't interfere with migrations.

Definition at line 371 of file libschema.php.

◆ dropIndexes()

fo_libschema::dropIndexes ( )

Delete indexes

Definition at line 403 of file libschema.php.

◆ dropViews()

fo_libschema::dropViews (   $catalog)

Delete views.

Get current tables and columns used by all views. Delete if: uses table I know and column I do not know. Without this delete, we won't be able to drop columns.

Parameters
string$catalogName of the catalog

Definition at line 504 of file libschema.php.

◆ exportSchema()

fo_libschema::exportSchema (   $filename = NULL)

Export the schema of the connected ($PG_CONN) database to a file in the format readable by GetSchema().

Parameters
string$filenamePath to the file to store the schema in.
Returns
false=success, on error return string with error message.

Definition at line 961 of file libschema.php.

◆ setDriver()

fo_libschema::setDriver ( Driver $dbDriver)

Set the Driver for the DbManager

Parameters
Driver$dbDriver

Definition at line 67 of file libschema.php.

◆ updateSequences()

fo_libschema::updateSequences ( )

Add sequences.

The function executes the UPDATE statement of the sequence.

See also
applySequences()

Definition at line 256 of file libschema.php.

◆ writeArrayEntries()

fo_libschema::writeArrayEntries (   $fout,
  $key,
  $value,
  $varname 
)

Write array entries to $fout as string representation

Parameters
resource$fout
string$key
array$value
string$varname

Definition at line 939 of file libschema.php.

Member Data Documentation

◆ $currSchema

array fo_libschema::$currSchema = array()
private

Current schema of the DB

Definition at line 52 of file libschema.php.

◆ $dbman

DbManager fo_libschema::$dbman
private

DB manager to use

Definition at line 40 of file libschema.php.

◆ $debug

bool fo_libschema::$debug = false

Set true to enable debugging

Definition at line 34 of file libschema.php.

◆ $schema

array fo_libschema::$schema = array()
private

Schema to be applied

Definition at line 46 of file libschema.php.


The documentation for this class was generated from the following file: