-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Changes from 7 commits
4203a7d
df5badc
2f18d7f
51b3472
42ba37a
87e55e4
5e25966
9ceb3c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' : | ||
$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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 139-141 Remove tab There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 163-165 Remove tab There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is missing closing |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.