srun/yii2-kingbase

Yii2 KingbaseES PostgreSQL-mode schema compatibility layer for SRun projects.

Maintainers

Package info

github.com/srunsoft/kingbase

pkg:composer/srun/yii2-kingbase

Transparency log

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-16 03:09 UTC

This package is auto-updated.

Last update: 2026-06-16 03:22:09 UTC


README

Yii2 KingbaseES PostgreSQL-mode schema compatibility layer.

This package provides a Yii2 database connection class for KingbaseES deployments that use the PostgreSQL-compatible PDO driver. It replaces Yii2's default PostgreSQL schema metadata query that calls pg_get_serial_sequence(...), which is not compatible with some KingbaseES environments.

Installation

composer require srun/yii2-kingbase:^1.0

Usage

Use the package connection class for Kingbase database components:

'components' => [
    'db' => [
        'class' => \srun\yii2\kingbase\Connection::class,
        'dsn' => 'pgsql:host=127.0.0.1;port=54321;dbname=srun4k',
        'username' => 'system',
        'password' => 'secret',
        'charset' => 'utf8',
    ],
],

The connection class extends yii\db\Connection and maps the pgsql driver to \srun\yii2\kingbase\Schema\KingbaseSchema.

If you need to keep using yii\db\Connection, you can configure the schema map explicitly:

'components' => [
    'db' => [
        'class' => \yii\db\Connection::class,
        'dsn' => 'pgsql:host=127.0.0.1;port=54321;dbname=srun4k',
        'username' => 'system',
        'password' => 'secret',
        'charset' => 'utf8',
        'schemaMap' => [
            'pgsql' => [
                'class' => \srun\yii2\kingbase\Schema\KingbaseSchema::class,
            ],
        ],
    ],
],

Why This Exists

Yii2's PostgreSQL schema metadata query normally includes:

pg_get_serial_sequence(quote_ident(d.nspname) || '.' || quote_ident(c.relname), a.attname) AS sequence_name

In validated KingbaseES PDO pgsql environments, that query can fail during schema inspection. This package replaces the expression with:

NULL::varchar AS sequence_name

Yii2 can still infer autoincrement behavior from column_default when it contains nextval(...), so standard ActiveRecord insert flows remain usable.

Scope

This package only solves framework-level schema metadata compatibility.

It does not include:

  • business table migrations
  • data cleanup SQL
  • service script fixes
  • authentication mode fixes
  • ClickHouse, Redis, or portal integration fixes

Verification Checklist

After enabling this package in a Yii2 project:

  • getTableSchema('migration') should work.
  • ActiveRecord insert operations with serial primary keys should work.
  • yii migrate --interactive=0 should run without the previous metadata error.
  • Schema cache can remain enabled after clearing old cache entries.

If the project previously cached broken schema metadata, clear runtime cache:

find runtime/cache -type f -delete

Requirements

  • PHP 7.4 or newer
  • Yii2 2.x
  • pdo_pgsql
  • pdo

License

MIT