yf_db_migrator_pgsql class

Fileplugins/db/classes/db/yf_db_migrator_pgsql.class.php
Use_class('db_migrator_pgsql', 'classes/db/')
Extendsyf_db_migrator

Public properties

A site sets them in its config with $PROJECT_CONF['db_migrator_pgsql']['NAME'] = ...;

PropertyDefaultDescription
$INT_TYPES
array
['tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'] Integer types: Postgres reports no length for them, MySQL the display width.

Inherited properties

from yf_db_migrator: $MIGRATIONS_TABLE, $STRICT_QUERY_ERRORS, $TRACK_MIGRATIONS, $db

Public methods 4

public function compare_column($c1, $c2)
    public function compare_column($c1, $c2)
    {
        if (in_array(strtolower((string) ($c1['type'] ?? '')), $this->INT_TYPES)) {
            unset($c1['length'], $c2['length']);
        }
        // no unsigned integers in Postgres: utils drop the attribute, so it never reads back
        unset($c1['unsigned'], $c2['unsigned']);
        return parent::compare_column($c1, $c2);
    }

Methods starting with _ hooks and helpers; not routable as page actions

public function _create_migrations_table()

Same table as the MySQL one, compiled through the Postgres utils.

    public function _create_migrations_table()
    {
        $table = $this->_migrations_table();
        $utils = $this->db->utils();
        if (in_array($table, (array) $utils->list_tables())) {
            return true;
        }
        $sql = $utils->_ddl_create_sql([
            'name' => $table,
            'fields' => [
                'id' => ['name' => 'id', 'type' => 'int', 'length' => 10, 'unsigned' => true, 'nullable' => false, 'auto_inc' => true],
                'name' => ['name' => 'name', 'type' => 'varchar', 'length' => 255, 'nullable' => false],
                'applied_at' => ['name' => 'applied_at', 'type' => 'datetime', 'nullable' => false],
            ],
            'indexes' => [
                'PRIMARY' => ['name' => 'PRIMARY', 'type' => 'primary', 'columns' => ['id' => 'id']],
                'name' => ['name' => 'name', 'type' => 'unique', 'columns' => ['name' => 'name']],
            ],
        ]);
        return $sql ? $this->db->query($sql) : false;
    }
public function _foreign_key_checks($enabled)

Postgres has no switch for foreign key checks, so the utils queue the foreign keys of created tables and cascade drops while a migration runs: the tables of a generated migration are not ordered by their references.

    public function _foreign_key_checks($enabled)
    {
        $utils = $this->db->utils();
        $utils->DEFER_FOREIGN_KEYS = ! $enabled;
        $utils->deferred_sql = [];
        return true;
    }
public function _run_deferred_queries()
    public function _run_deferred_queries()
    {
        $utils = $this->db->utils();
        $queue = $utils->deferred_sql;
        $utils->deferred_sql = [];
        foreach ($queue as $sql) {
            $this->db->query($sql);
        }
    }

Inherited methods

from yf_db_migrator: __call(), _applied(), _cleanup_column_sql_php(), _cleanup_table_sql_php(), _convert_sql_php_into_sql(), _create_migration_body(), _dump_sql_file_body(), _get_migration_model(), _list(), _load_migration(), _load_tables_sql_php_from_files(), _migration_commands_into_string(), _migrations_table(), _rollback_one(), _run_migration(), _write_dump_sql_file(), _write_dump_sql_php_file(), _write_new_migration_file(), apply(), apply_migration(), compare(), compare_foreign_key(), compare_index(), compare_table(), create(), create_migration(), dump(), dump_db_installer_sql(), dump_sql_php(), generate(), generate_down(), generate_migration(), generate_up(), get_real_table_sql_php(), list_migrations(), reset(), rollback(), sync(), sync_sql_php()