2

I've managed to convert a fairly basic Craft 4 MySQL db to PostgreSQL using the pgloader tool, which came with it's own auth related issues when running PSQL v14+ instance - see https://github.com/dimitri/pgloader/issues/1183 for solution, but it ran successfully in the end. Now when attempting to view the site locally it's throwing the following error, an issue with Craft specifically it seems:

yii\base\UnknownPropertyException: Setting unknown property: craft\models\Info::schemaversion in /var/www/html/vendor/yiisoft/yii2/base/Component.php:209
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set('schemaversion', '4.0.0.9')

Also I tried dropping/recreating the pg db and installing a fresh craft instance with ./craft install/craft but that output the following:

    > populating the info table ... Exception: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "ORDER"

*** failed to install Craft: An error occurred while executing the "craft\migrations\Install migration: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "ORDER"
LINE 60: ORDER BY
         ^
The SQL being executed was: SELECT
    d.nspname AS table_schema,
    c.relname AS table_name,
    a.attname AS column_name,
    COALESCE(td.typname, tb.typname, t.typname) AS data_type,
    COALESCE(td.typtype, tb.typtype, t.typtype) AS type_type,
    (SELECT nspname FROM pg_namespace WHERE oid = COALESCE(td.typnamespace, tb.typnamespace, t.typnamespace)) AS type_scheme,
    a.attlen AS character_maximum_length,
    pg_catalog.col_description(c.oid, a.attnum) AS column_comment,
    a.atttypmod AS modifier,
    a.attnotnull = false AS is_nullable,
    CAST(pg_get_expr(ad.adbin, ad.adrelid) AS varchar) AS column_default,
    coalesce(pg_get_expr(ad.adbin, ad.adrelid) ~ 'nextval',false) OR attidentity != '' AS is_autoinc,
    pg_get_serial_sequence(quote_ident(d.nspname) || '.' || quote_ident(c.relname), a.attname) AS sequence_name,
    CASE WHEN COALESCE(td.typtype, tb.typtype, t.typtype) = 'e'::char
        THEN array_to_string((SELECT array_agg(enumlabel) FROM pg_enum WHERE enumtypid = COALESCE(td.oid, tb.oid, a.atttypid))::varchar[], ',')
        ELSE NULL
    END AS enum_values,
    CASE atttypid
         WHEN 21 /*int2*/ THEN 16
         WHEN 23 /*int4*/ THEN 32
         WHEN 20 /*int8*/ THEN 64
         WHEN 1700 /*numeric*/ THEN
              CASE WHEN atttypmod = -1
               THEN null
               ELSE ((atttypmod - 4) >> 16) & 65535
               END
         WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/
         WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/
         ELSE null
      END   AS numeric_precision,
      CASE
        WHEN atttypid IN (21, 23, 20) THEN 0
        WHEN atttypid IN (1700) THEN
        CASE
            WHEN atttypmod = -1 THEN null
            ELSE (atttypmod - 4) & 65535
        END
           ELSE null
      END AS numeric_scale,
    CAST(
             information_schema._pg_char_max_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t))
             AS numeric
    ) AS size,
    a.attnum = any (ct.conkey) as is_pkey,
    COALESCE(NULLIF(a.attndims, 0), NULLIF(t.typndims, 0), (t.typcategory='A')::int) AS dimension
FROM
    pg_class c
    LEFT JOIN pg_attribute a ON a.attrelid = c.oid
    LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
    LEFT JOIN pg_type t ON a.atttypid = t.oid
    LEFT JOIN pg_type tb ON (a.attndims > 0 OR t.typcategory='A') AND t.typelem > 0 AND t.typelem = tb.oid OR t.typbasetype > 0 AND t.typbasetype = tb.oid
    LEFT JOIN pg_type td ON t.typndims > 0 AND t.typbasetype > 0 AND tb.typelem = td.oid
    LEFT JOIN pg_namespace d ON d.oid = c.relnamespace
    LEFT JOIN pg_constraint ct ON ct.conrelid = c.oid AND ct.contype = 'p'
WHERE
    a.attnum > 0 AND t.typname != '' AND NOT a.attisdropped
    AND c.relname = 'info'
    AND d.nspname = 
ORDER BY
    a.attnum;

I'm running PostgreSQL server 15.1 (Debian 15.1-1.pgdg110+1)).

Any help appreciated, thanks!

1 Answer 1

0

That error is because the config/db.php file is probably setting the schema property to an empty string (or null), overwriting the default public value that Postgres uses.

4
  • Thanks Brad! That sorted it, silly me - I'd commented out the DB_SCHEMA env var. Wrt to setting the unknown property 'schemaVersion', that related to the lowercase conversion when using the pgloader from to in it's rawest form. Reverted to your answer in a similar q which resolved it, using a command file as the input - thanks for your help!
    – Rich D.
    Commented Dec 15, 2022 at 22:39
  • No worries - glad you're all sorted!
    – Brad Bell
    Commented Dec 16, 2022 at 2:25
  • @BradBell what else could it be? I get the same php error like @Rich D. but with different stack trace start. An Error occurred while handling another error: yii\base\UnknownPropertyException: Setting unknown property: craft\models\Info::schemaversion in /app/vendor/yiisoft/yii2/base/Component.php:209 Stack trace: #0 /app/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set() #1 /app/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure() Commented Feb 6, 2023 at 19:07
  • A note to add to my comment above is that I migrated using Docker command because databases live in Docker containers. So I run something like $ docker run --rm -it dimitri/pgloader:latest pgloader mysql://myuser@myhost/dbname pgsql://pguser@pghost/dbname. After I just renamed schema name to public. I quote your comment in your question: column names would all be lowercased, some critical type conversions and search index updates would be missing. Could that be? Commented Feb 6, 2023 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.