Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[postgresql] - schema change rework #18483

Closed
wants to merge 8 commits into from
Closed
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 77 additions & 59 deletions libraries/src/Schema/ChangeItem/PostgresqlChangeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,72 +85,90 @@ protected function buildCheckQuery()
}
elseif ($alterCommand === 'ALTER COLUMN')
{
if (strtoupper($wordArray[6]) === 'TYPE')
switch (strtoupper($wordArray[6]))
{
$type = '';
case 'TYPE' :
$type = '';

for ($i = 7, $iMax = count($wordArray); $i < $iMax; $i++)
{
$type .= $wordArray[$i] . ' ';
}
for ($i = 7; $i < count($wordArray); $i++)
{
$type .= $wordArray[$i] . ' ';
}

if ($pos = strpos($type, '('))
{
$type = substr($type, 0, $pos);
}
if ($pos = strpos($type, '('))
{
$type = substr($type, 0, $pos);
}

if ($pos = strpos($type, ';'))
{
$type = substr($type, 0, $pos);
}
if ($pos = strpos($type, ';'))
{
$type = substr($type, 0, $pos);
}

$result = 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND data_type=' . $this->fixQuote($type);
$result = 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND data_type=' . $this->fixQuote($type);

$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $type);
}
elseif (strtoupper($wordArray[7] . ' ' . $wordArray[8]) === 'NOT NULL')
{
if (strtoupper($wordArray[6]) === 'SET')
{
// SET NOT NULL
$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $type);
break;

case 'SET' :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line before line 115.

$isNullable = $this->fixQuote('NO');
}
else
{
// DROP NOT NULL
$isNullable = $this->fixQuote('YES');
}

$result = 'SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND is_nullable=' . $isNullable;

$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->checkQueryExpected = 1;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullable);
}
elseif (strtoupper($wordArray[7]) === 'DEFAULT')
{
if (strtoupper($wordArray[6]) === 'SET')
{
$isNullDef = 'IS NOT NULL';
}
else
{
// DROP DEFAULT
$isNullDef = 'IS NULL';
}

$result = 'SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND column_default ' . $isNullDef;

$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->checkQueryExpected = 1;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullDef);
if (strtoupper($wordArray[7] . ' ' . $wordArray[8]) === 'NOT NULL;')
{
$result = 'SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND is_nullable=' . $isNullable;

$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->checkQueryExpected = 1;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullable);
}

if (strtoupper($wordArray[6] . ' ' . $wordArray[7]) === 'SET DEFAULT')
{
$string = str_replace(';', '', $wordArray[8]);
$result = 'SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name='
. $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND (CASE (position(' . $this->db->quote('::') . ' in column_default))'
. ' WHEN 0 THEN '
. ' column_default = ' . $this->db->quote($string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent lines 136-139.

. ' ELSE '
. ' substring(column_default, 1, (position(' . $this->db->quote('::') . ' in column_default) -1)) = ' . $this->db->quote($string)
. ' END)';

$this->queryType = 'CHANGE_COLUMN_TYPE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 139-141 Remove tab

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above.

$this->checkQueryExpected = 1;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $this->fixQuote($wordArray[8]));
}
break;

case 'DROP' :
if ($wordArray[7] === 'DEFAULT')
{
$isNullable = $this->fixQuote('NO');
$result = 'SELECT column_name, data_type, is_nullable , column_default FROM information_schema.columns'
. ' WHERE table_name=' . $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND column_default IS NULL';

$this->queryType = 'CHANGE_COLUMN_TYPE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above.

$this->checkQueryExpected = 1;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), 'DEFAULT');
}

if ($wordArray[7] . ' ' . $wordArray[8] === 'NOT NULL;')
{
$isNullable = $this->fixQuote('NO');
$result = 'SELECT column_name, data_type, is_nullable , column_default FROM information_schema.columns'
. ' WHERE table_name=' . $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5])
. ' AND is_nullable = ' . $isNullable;

$this->queryType = 'CHANGE_COLUMN_TYPE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 163-165 Remove tab

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above.

$this->checkQueryExpected = 0;
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), 'NOT NULL');
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is missing closing } to the switch statement.

}
}
}
Expand Down