Skip to content

Instantly share code, notes, and snippets.

@dbrkv
Forked from dextervip/PostgreSqlPlatform.php
Created April 19, 2021 21:39
Show Gist options
  • Select an option

  • Save dbrkv/297097727ec3655db549cbe6fa9cac5b to your computer and use it in GitHub Desktop.

Select an option

Save dbrkv/297097727ec3655db549cbe6fa9cac5b to your computer and use it in GitHub Desktop.

Revisions

  1. @dextervip dextervip revised this gist Apr 21, 2020. 1 changed file with 0 additions and 39 deletions.
    39 changes: 0 additions & 39 deletions PostgreSqlPlatform.php
    Original file line number Diff line number Diff line change
    @@ -49,43 +49,4 @@ public function getListTablesSQL()
    AND table_type != 'VIEW'";
    }


    /**
    * {@inheritDoc}
    */
    /* public function getListTableColumnsSQL($table, $database = null)
    {
    return "SELECT
    a.attnum,
    quote_ident(a.attname) AS field,
    t.typname AS type,
    format_type(a.atttypid, a.atttypmod) AS complete_type,
    (SELECT t1.typname FROM pg_catalog.pg_type t1 WHERE t1.oid = t.typbasetype) AS domain_type,
    (SELECT format_type(t2.typbasetype, t2.typtypmod) FROM
    pg_catalog.pg_type t2 WHERE t2.typtype = 'd' AND t2.oid = a.atttypid) AS domain_complete_type,
    a.attnotnull AS isnotnull,
    (SELECT 't'
    FROM pg_index
    WHERE c.oid = pg_index.indrelid
    AND pg_index.indkey[0] = a.attnum
    AND pg_index.indisprimary = 't'
    ) AS pri,
    (SELECT pg_get_expr(adbin, adrelid)
    FROM pg_attrdef
    WHERE c.oid = pg_attrdef.adrelid
    AND pg_attrdef.adnum=a.attnum
    ) AS default,
    (SELECT pg_description.description
    FROM pg_description WHERE pg_description.objoid = c.oid AND a.attnum = pg_description.objsubid
    ) AS comment
    FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n
    WHERE " . $this->getTableWhereClause($table, 'c', 'n') . '
    AND a.attnum > 0
    AND a.attrelid = c.oid
    AND a.atttypid = t.oid
    AND n.oid = c.relnamespace
    AND n.nspname NOT LIKE \'%timescaledb%\'
    ORDER BY a.attnum';
    }*/

    }
  2. @dextervip dextervip revised this gist Apr 21, 2020. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions doctrine.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    doctrine:
    dbal:
    url: '%env(resolve:DATABASE_URL)%'

    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    server_version: '11'
    platform_service: App\Domain\Doctrine\DBAL\Platforms\PostgreSqlPlatform
  3. @dextervip dextervip created this gist Apr 21, 2020.
    91 changes: 91 additions & 0 deletions PostgreSqlPlatform.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    <?php


    namespace App\Domain\Doctrine\DBAL\Platforms;

    use Doctrine\DBAL\Platforms\PostgreSQL100Platform as PostgreSqlPlatformBase;

    class PostgreSqlPlatform extends PostgreSqlPlatformBase
    {

    /**
    * {@inheritDoc}
    */
    public function getListNamespacesSQL()
    {
    return "SELECT schema_name AS nspname
    FROM information_schema.schemata
    WHERE schema_name NOT LIKE 'pg\_%'
    AND schema_name NOT LIKE '%timescaledb%'
    AND schema_name != 'information_schema'";
    }

    public function getListSequencesSQL($database) : string
    {
    return 'SELECT sequence_name AS relname,
    sequence_schema AS schemaname,
    minimum_value AS min_value,
    increment AS increment_by
    FROM information_schema.sequences
    WHERE sequence_catalog = ' . $this->quoteStringLiteral($database) . "
    AND sequence_schema NOT LIKE 'pg\_%'
    AND sequence_schema NOT LIKE '%timescaledb\_%'
    AND sequence_schema != 'information_schema'";
    }

    /**
    * {@inheritDoc}
    */
    public function getListTablesSQL()
    {
    return "SELECT quote_ident(table_name) AS table_name,
    table_schema AS schema_name
    FROM information_schema.tables
    WHERE table_schema NOT LIKE 'pg\_%'
    AND table_schema NOT LIKE '%timescaledb%'
    AND table_schema != 'information_schema'
    AND table_name != 'geometry_columns'
    AND table_name != 'spatial_ref_sys'
    AND table_type != 'VIEW'";
    }


    /**
    * {@inheritDoc}
    */
    /* public function getListTableColumnsSQL($table, $database = null)
    {
    return "SELECT
    a.attnum,
    quote_ident(a.attname) AS field,
    t.typname AS type,
    format_type(a.atttypid, a.atttypmod) AS complete_type,
    (SELECT t1.typname FROM pg_catalog.pg_type t1 WHERE t1.oid = t.typbasetype) AS domain_type,
    (SELECT format_type(t2.typbasetype, t2.typtypmod) FROM
    pg_catalog.pg_type t2 WHERE t2.typtype = 'd' AND t2.oid = a.atttypid) AS domain_complete_type,
    a.attnotnull AS isnotnull,
    (SELECT 't'
    FROM pg_index
    WHERE c.oid = pg_index.indrelid
    AND pg_index.indkey[0] = a.attnum
    AND pg_index.indisprimary = 't'
    ) AS pri,
    (SELECT pg_get_expr(adbin, adrelid)
    FROM pg_attrdef
    WHERE c.oid = pg_attrdef.adrelid
    AND pg_attrdef.adnum=a.attnum
    ) AS default,
    (SELECT pg_description.description
    FROM pg_description WHERE pg_description.objoid = c.oid AND a.attnum = pg_description.objsubid
    ) AS comment
    FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n
    WHERE " . $this->getTableWhereClause($table, 'c', 'n') . '
    AND a.attnum > 0
    AND a.attrelid = c.oid
    AND a.atttypid = t.oid
    AND n.oid = c.relnamespace
    AND n.nspname NOT LIKE \'%timescaledb%\'
    ORDER BY a.attnum';
    }*/

    }