Overview

Namespaces

  • Composer
    • Autoload
  • Geekwright
    • RegDom
  • League
    • OAuth2
      • Client
        • Provider
  • None
  • Xmf
    • Database
    • Jwt
    • Key
    • Module
      • Helper

Classes

  • Migrate
  • TableLoad
  • Tables
  • Overview
  • Namespace
  • Class
  • Tree

Class Migrate

Xmf\Database\Migrate

For a given module, compare the existing tables with a defined target schema and build a work queue of DDL/SQL to transform the existing tables to the target definitions.

Typically Migrate will be extended by a module specific class that will supply custom logic (see preSyncActions() method.)

Namespace: Xmf\Database
Package: Xmf
Category: Xmf\Database\Migrate
Copyright: 2016 XOOPS Project (http://xoops.org)
License: GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
Author: Richard Griffith richard@geekwright.com
Link: http://xoops.org
Located at lass/libraries/vendor/xoops/xmf/src/Xmf/Database/Migrate.php
Methods summary
public
# __construct( string $dirname )

Migrate constructor

Migrate constructor

Parameters

$dirname
module directory name that defines the tables to be migrated

Throws

InvalidArgumentException
RuntimeException
public integer|false
# saveCurrentSchema( )

Save current table definitions to a file

Save current table definitions to a file

This is intended for developer use when setting up the migration by using the current database state

Returns

integer|false
count of bytes written or false on error
public array
# getCurrentSchema( )

get the current definitions

get the current definitions

Returns

array
public array|boolean
# getTargetDefinitions( )

Return the target database condition

Return the target database condition

Returns

array|boolean
table structure or false on error

Throws

RuntimeException
public boolean
# synchronizeSchema( boolean $force = true )

Execute synchronization to transform current schema to target

Execute synchronization to transform current schema to target

Parameters

$force
true to force updates even if this is a 'GET' request

Returns

boolean
true if no errors, false if errors encountered
public string[]
# getSynchronizeDDL( )

Compare target and current schema, building work queue in $this->migrate to synchronized

Compare target and current schema, building work queue in $this->migrate to synchronized

Returns

string[]
array of DDL/SQL statements to transform current to target schema
protected
# preSyncActions( )

Perform any upfront actions before synchronizing the schema.

Perform any upfront actions before synchronizing the schema.

The schema comparison cannot recognize changes such as renamed columns or renamed tables. By overriding this method, an implementation can provide the logic to accomplish these types of changes, and leave the other details to be handled by synchronizeSchema().

An suitable implementation should be provided by a module by extending Migrate to define any required actions.

Some typical uses include: - table and column renames - data conversions - move column data

protected
# addMissingTable( string $tableName )

Add table create DDL to the work queue

Add table create DDL to the work queue

Parameters

$tableName
table to add
protected
# synchronizeTable( string $tableName )

Build any DDL required to synchronize an existing table to match the target schema

Build any DDL required to synchronize an existing table to match the target schema

Parameters

$tableName
table to synchronize
protected boolean
# targetHasColumn( string $tableName, string $columnName )

determine if a column on a table exists in the target definitions

determine if a column on a table exists in the target definitions

Parameters

$tableName
table containing the column
$columnName
column to check

Returns

boolean
true if table and column combination is defined, otherwise false
protected boolean
# targetHasTable( string $tableName )

determine if a table exists in the target definitions

determine if a table exists in the target definitions

Parameters

$tableName
table containing the column

Returns

boolean
true if table is defined, otherwise false
public string
# getLastError( )

Return message from last error encountered

Return message from last error encountered

Returns

string
last error message
public integer
# getLastErrNo( )

Return code from last error encountered

Return code from last error encountered

Returns

integer
last error number
Properties summary
protected false|Xmf\Module\Helper|Xoops\Module\Helper\HelperAbstract $helper
#
protected string[] $moduleTables

table names used by module

table names used by module

#
protected Xmf\Database\Tables $tableHandler
#
protected string $tableDefinitionFile

yaml definition file

yaml definition file

#
protected array $targetDefinitions

target table definitions in Xmf\Database\Tables::dumpTables() format

target table definitions in Xmf\Database\Tables::dumpTables() format

#
API documentation generated by ApiGen