Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created January 6, 2015 06:01
Show Gist options
  • Save tikitikipoo/2af4f9804da7f2619063 to your computer and use it in GitHub Desktop.
Save tikitikipoo/2af4f9804da7f2619063 to your computer and use it in GitHub Desktop.
app/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/Database/Postgres.php
556行目
if ($boolToInt) {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' SET DEFAULT NULL';
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)) . ' USING CASE WHEN TRUE THEN 1 ELSE 0 END';
} else {
if ($original['type'] === 'text' && $col['type'] === 'integer') {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)) . " USING cast({$fieldName} as INTEGER)";
} else if ($original['type'] === 'integer' && $col['type'] === 'boolean') {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)) . " USING cast({$fieldName} as BOOLEAN)";
} else if ($original['type'] === 'datetime' && $col['type'] === 'integer') {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)) . " USING EXTRACT(EPOCH FROM {$fieldName})";
} else if ($original['type'] === 'integer' && $col['type'] === 'datetime') {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)) . " USING timestamp with time zone 'epoch' + {$fieldName} * interval '1 second'";
} else {
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment