/** * @param string $tableName * @param string $columnName * @param \Doctrine\DBAL\Schema\Column $column * @return array */ protected function getAddColumnSQL($tableName, $columnName, Column $column) { $query = array(); $spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false); foreach ($spatial as $key => &$val) { if ($column->hasCustomSchemaOption('spatial_' . $key)) { $val = $column->getCustomSchemaOption('spatial_' . $key); } } // Geometry columns are created by AddGeometryColumn stored procedure $query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']); if ($spatial['index']) { // Add a spatial index to the field $query[] = sprintf("Select CreateSpatialIndex('%s', '%s')", $tableName, $columnName); } return $query; }
/** * @param string $tableName * @param string $columnName * @param \Doctrine\DBAL\Schema\Column $column * @return array */ protected function getAddColumnSQL($tableName, $columnName, Column $column) { $query = array(); $spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false); foreach ($spatial as $key => &$val) { if ($column->hasCustomSchemaOption('spatial_' . $key)) { $val = $column->getCustomSchemaOption('spatial_' . $key); } } // Geometry columns are created by AddGeometryColumn stored procedure $query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']); if ($spatial['index']) { // Add a spatial index to the field $indexName = $this->generateIndexName($tableName, $columnName); $query[] = sprintf("CREATE INDEX %s ON %s USING GIST (%s)", $indexName, $tableName, $columnName); } if ($column->getNotnull()) { // Add a NOT NULL constraint to the field $query[] = sprintf("ALTER TABLE %s ALTER %s SET NOT NULL", $tableName, $columnName); } return $query; }