mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Fixing schema generation for postgres. Now character varying without lenght is translated to "text", to avoid sql errors. Closes #564
This commit is contained in:
parent
e2b5470d19
commit
9d2819970d
2 changed files with 9 additions and 1 deletions
|
@ -231,7 +231,12 @@ class DboPostgres extends DboSource {
|
||||||
if (!empty($c['char_length'])) {
|
if (!empty($c['char_length'])) {
|
||||||
$length = intval($c['char_length']);
|
$length = intval($c['char_length']);
|
||||||
} elseif (!empty($c['oct_length'])) {
|
} elseif (!empty($c['oct_length'])) {
|
||||||
$length = intval($c['oct_length']);
|
if ($c['type'] == 'character varying') {
|
||||||
|
$length = null;
|
||||||
|
$c['type'] = 'text';
|
||||||
|
} else {
|
||||||
|
$length = intval($c['oct_length']);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$length = $this->length($c['type']);
|
$length = $this->length($c['type']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,6 +567,7 @@ class DboPostgresTest extends CakeTestCase {
|
||||||
$db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' (
|
$db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' (
|
||||||
id serial NOT NULL,
|
id serial NOT NULL,
|
||||||
"varchar" character varying(40) NOT NULL,
|
"varchar" character varying(40) NOT NULL,
|
||||||
|
"full_length" character varying NOT NULL,
|
||||||
"timestamp" timestamp without time zone,
|
"timestamp" timestamp without time zone,
|
||||||
date date,
|
date date,
|
||||||
CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id)
|
CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id)
|
||||||
|
@ -579,7 +580,9 @@ class DboPostgresTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$schema->tables = array('datatypes' => $result['tables']['datatypes']);
|
$schema->tables = array('datatypes' => $result['tables']['datatypes']);
|
||||||
$result = $db1->createSchema($schema, 'datatypes');
|
$result = $db1->createSchema($schema, 'datatypes');
|
||||||
|
|
||||||
$this->assertNoPattern('/timestamp DEFAULT/', $result);
|
$this->assertNoPattern('/timestamp DEFAULT/', $result);
|
||||||
|
$this->assertPattern('/\"full_length\"\s*text\s.*,/', $result);
|
||||||
$this->assertPattern('/timestamp\s*,/', $result);
|
$this->assertPattern('/timestamp\s*,/', $result);
|
||||||
|
|
||||||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatypes'));
|
$db1->query('DROP TABLE ' . $db1->fullTableName('datatypes'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue