Unknown database type json requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it - postgresql

Developing using Symfony 2.7
I have entity which contain attribute
/**
* #var array
* #ORM\Column(name="new_entry_name", type="json_array", nullable=true)
*/
protected $newEntryName;
but when i update my schema using
php app/console doctrine:schema:update --force
it shows me error
$ php app/console doctrine:schema:update --force
[Doctrine\DBAL\DBALException]
Unknown database type json requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it.
In config.yml file i have added this type.
doctrine:
dbal:
driver: "pdo_pgsql"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
set: string
varbinary: string
tinyblob: text
types:
json: Sonata\Doctrine\Types\JsonType
what should i do to avoid this error .Thanks

To avoid this error add
json: json_array
or
json: json
in config.yml under mapping_types section.
So, mapping_types section should look like this:
mapping_types:
enum: string
set: string
varbinary: string
tinyblob: text
json: json_array

Related

Azure Database for PostgreSQL flexible server deployment fails with databaseName param error

I'm trying to deploy PostgreSQL managed service with bicep and in most cases get an error:
"code": "InvalidParameterValue",
"message": "Invalid value given for parameter databaseName. Specify a valid parameter value."
I've tried various names for the DB, even in last version of the script I add random suffix to made it unique. Anyway it finishes with error, but looks like service is working. Another unexplainable thing is that sometimes script finishes without error... It's part of my IaC scenario, i need to be able to rerun it many times...
bicep code:
param location string
#secure()
param sqlserverLoginPassword string
param rand string = uniqueString(resourceGroup().id) // Generate unique String
param sqlserverName string = toLower('invivopsql-${rand}')
param sqlserverAdminName string = 'invivoadmin'
param psqlDatabaseName string = 'postgres'
resource flexibleServer 'Microsoft.DBforPostgreSQL/flexibleServers#2021-06-01' = {
name: sqlserverName
location: location
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
properties: {
createMode: 'Default'
version: '13'
administratorLogin: sqlserverAdminName
administratorLoginPassword: sqlserverLoginPassword
availabilityZone: '1'
storage: {
storageSizeGB: 32
}
backup: {
backupRetentionDays: 7
geoRedundantBackup: 'Disabled'
}
}
}
Please follow this git issue here for a similar error that might help you to fix your problem.

symfony - configure postgres entity manager

I would like to change the database in my existing project from mysql to postgresql.
I have configured the database, I have regenerated the migrations which work, but the problem appears in the fixtures.
when trying to load fixtures an error appears like this:
An exception occurred while executing 'INSERT INTO user (nickname, password, id, created_at, updated_at, email) VALUES (?, ?, ?, ?, ?, ?)' with params ["user", "$2y$13$rgHtT56Vlk2
avmf3gX2W7.QYcQ5d6AXRzr41ebRMGfxREqLZQfsTG", "017c4562-d487-ddff-c303-108c1916d6dd", "2021-10-03 11:01:16", "2021-10-03 11:01:16", "user#user.pl"]:
SQLSTATE[42601]: Syntax error: 7 BŁĄD: błąd składni w lub blisko "user"
LINE 1: INSERT INTO user (nickname, password, id, created_at, update... ,
this is a problem possibly caused by entity manager generating the mysql dialect instead of postgres dialect.
a similar error occurs during the get shot under the user entity:
"hydra:description": "An exception occurred while executing 'SELECT u0_.nickname AS nickname_0, u0_.password AS password_1, u0_.id AS id_2, u0_.created_at AS created_at_3, u0_.updated_at AS updated_at_4, u0_.email AS email_5 FROM user u0_':\n\nSQLSTATE[42703]: Undefined column: 7 BŁĄD: kolumna u0_.nickname nie istnieje\nLINE 1: SELECT u0_.nickname AS nickname_0, u0_.password AS password_.
Here is my doctrine.yaml configuration:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_pgsql'
charset: utf8
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
Could someone help me get rid of the bug? :)

Cannot pass dynamic query parameters when using `express-openapi-validator`

The idea is taken from here stack-overflow
After adding a parameter that is supposed do allow dynamic query parameters, it gives error.
Query Example:
/pets:
get:
description: |
Returns all pets
operationId: findPets
parameters:
- name: params
in: query
required: false
schema:
type: object
# If the parameter values are of specific type, e.g. string:
# additionalProperties:
# type: string
# If the parameter values can be of different types
# (e.g. string, number, boolean, ...)
additionalProperties: true
# `style: form` and `explode: true` is the default serialization method
# for query parameters, so these keywords can be omitted
style: form
explode: true
responses:
'200':
description: pet response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Executing a query, returns
{"message":"Cannot convert undefined or null to object"}
To Reproduce
Clone this repository
run npm install
run npm start
run curl http://localhost:3000/v1/pets\?type\=dog\&limit\=10\&test\=query
Expected behavior
It must allow all the query strings
This was the bug in the express-openapi-validator package.
It is now fixed in v4.4.2
To test out the functionality, see this example project

Knex is not reading connection string from knexfile

I have been given a knexfile like this:
require('dotenv').config()
module.exports = {
client: 'pg',
connection: process.env.DB_CONNECTION,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
};
The connection string I supply is:
Host=localhost;Database=heypay;Username=postgres;Password=1234
However, Knex keeps issuing the error:
password authentication failed for user "user"
Apparently, the username I have given is not user. Moreover, I have tried to hardcore the connection string into the connection filed under module.exports. This still ended up in vain.
The trick is, the connection property can either be a string or an object. That's why you were able to supply an environment variable (it's a string).
The reason your original string was failing is not a Knex problem: Postgres connection strings have a slightly different format. You can use a similar approach as your first attempt, but pay attention to the key names:
host=localhost port=5432 dbname=mydb connect_timeout=10
Also note spaces, not semicolons. However in my experience most people use a Postgres URI:
postgresql://[user[:password]#][netloc][:port][,...][/dbname][?param1=value1&...]
So in your example, you'd use:
module.exports = {
client: 'pg',
connection: 'postgresql://your_database_user:password#localhost/myapp_test',
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
};
I was using a .NET style connection string, the correct one would be in the following format:
{
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}

How to fix "Unknown database type geometry requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it."

I am trying to prepare Symfony 3.4.32 + PostgreSQL + PostGIS environment.
I installed jsor/doctrine-postgis, but the error following happens.
Unknown database type geometry requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.
Details
I am using EC-CUBE 4.0.3 which is open source software using Symfony 3.4.32 .
I prepared mdillon/postgis docker container.
I enable postgis extension and I can use PostGIS.
I installed jsor/doctrine-postgis by composer and set up config files.
I added the setting to the bottom of app/config/eccube/services.yaml.
services:
# (ommitted)
Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber:
tags:
- { name: doctrine.event_subscriber, connection: default }
I add the three types (geography, geometry, raster) to app/config/eccube/packages/doctrine.yaml.
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
env(DATABASE_SERVER_VERSION): ~
doctrine:
dbal:
driver: 'pdo_pgsql'
server_version: "%env(DATABASE_SERVER_VERSION)%"
charset: utf8
# for mysql only
default_table_options:
collate: 'utf8_general_ci'
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(DATABASE_URL)%'
# types
types:
datetime: 'Eccube\Doctrine\DBAL\Types\UTCDateTimeType'
datetimetz: 'Eccube\Doctrine\DBAL\Types\UTCDateTimeTzType'
geography:
class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
commented: false
geometry:
class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
commented: false
raster:
class: 'Jsor\Doctrine\PostGIS\Types\RasterType'
commented: false
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
NORMALIZE: Eccube\Doctrine\ORM\Query\Normalize
numeric_functions:
EXTRACT: Eccube\Doctrine\ORM\Query\Extract
filters:
option_nostock_hidden:
class: Eccube\Doctrine\Filter\NoStockHiddenFilter
enabled: false
incomplete_order_status_hidden:
class: Eccube\Doctrine\Filter\OrderStatusFilter
enabled: false
I prepared Entity, app/Customize/Entity/Geolocation.php.
<?php
namespace Customize\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* GeoLocation
*
* #ORM\Table(name="dtb_geolocation")
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
* #ORM\HasLifecycleCallbacks()
* #ORM\Entity(repositoryClass="Customize\Repository\GeoLocationRepository")
*/
class GeoLocation extends \Eccube\Entity\AbstractEntity
{
/**
* #ORM\Column(name="gid", type="integer", options={"unsigned":true})
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
public $gid;
// (ommitted)
/**
* #ORM\Column(name="geom", type="geometry", options={"geometry_type"="MULTIPOLYGON", "srid"=4612}, nullable=true)
*/
public $geom;
}
Then I created the table in PostgreSQL database.
Run
bin/console eccube:generate:proxies
bin/console doctrine:schema:update --dump-sql --force
It works fine. "dtb_geolocation" table is created and checked it in PostgreSQL.
db=# \d dtb_geolocation ;
Table "public.dtb_geolocation "
Column | Type | Collation | Nullable | Default
--------------------+-----------------------------+-----------+----------+-----------------------------------------------------------
gid | integer | | not null | nextval('dtb_geolocation_pkey'::regclass)
// ommitted
geom | geometry(MultiPolygon,4612) | | | NULL::geometry
discriminator_type | character varying(255) | | not null |
Indexes:
"dtb_geolocation_pkey" PRIMARY KEY, btree (gid)
But when I accessed on brower, the error happens.
Unknown database type geometry requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.
I clear caches by bin/console cache:clear --no-warmup, but nothing changes.
Did I make any mistakes?
Aren't geometry type included in Symfony? How can I check it?
Maybe this is an EC-CUBE 4 problem.
I guess the doctrine.yaml is loaded after Symfony recognizes database tables.