class DatabaseSchemaService (View source)

Methods

__construct(PDO $db)

No description

array
listTables()

List all tables in the current database

void
createTable(string $name, array $fields, array $options = array())

Create a new table

void
createIndexes(string $tableName, array $indexes)

Create the secondary indexes declared for a table.

void
createForeignKeys(string $tableName, array $foreignKeys)

Add the foreign keys declared for a table via ALTER TABLE. Call after every table exists.

void
executeMultiple(PDOStatement $stmt, array $params)

Execute multiple prepared statement operations with different parameter sets

void
dropTable(string $name)

Drop an existing table

Details

__construct(PDO $db)

No description

Parameters

PDO $db

array listTables()

List all tables in the current database

Return Value

array

void createTable(string $name, array $fields, array $options = array())

Create a new table

Parameters

string $name

Name of the table that should be created

array $fields

Associative array that contains the definition of each field of the new table

array $options

An associative array of table options

Return Value

void

void createIndexes(string $tableName, array $indexes)

Create the secondary indexes declared for a table.

Accepts both structure-array shapes: nested (['fields' => ['col' => []], 'type' => 'unique']) and flat (['col1', 'col2', 'unique' => true]). On PostgreSQL/SQLite index names are schema-global, so a name that doesn't already carry the table name is prefixed with it to avoid collisions between the generic names the structure array reuses across tables.

Parameters

string $tableName
array $indexes

Map of index name => definition

Return Value

void

void createForeignKeys(string $tableName, array $foreignKeys)

Add the foreign keys declared for a table via ALTER TABLE. Call after every table exists.

SQLite is skipped: it can only declare foreign keys inline at CREATE TABLE time (no ALTER TABLE ADD CONSTRAINT), matching the installer's long-standing behavior there.

Parameters

string $tableName
array $foreignKeys

Map of constraint name => ['table' => ref, 'fields' => [local => ref], 'ondelete'?, 'onupdate'?]

Return Value

void

void executeMultiple(PDOStatement $stmt, array $params)

Execute multiple prepared statement operations with different parameter sets

Parameters

PDOStatement $stmt

Prepared statement

array $params

Array of parameter arrays

Return Value

void

void dropTable(string $name)

Drop an existing table

Parameters

string $name

name of the table that should be dropped

Return Value

void