Loading src/UnicaenDbImport/CodeGenerator/CodeGenerator.php +21 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,27 @@ abstract class CodeGenerator implements CodeGeneratorInterface return $this->tableValidationHelper->convertHistoColumnsValidationBadResultToException($tableName, $result); } /** * @param string $tableName * @return string * @codeCoverageIgnore Car simple délégation */ public function generateSQLForSourceColumnsValidation($tableName) { return $this->tableValidationHelper->generateSQLForSourceColumnsValidation($tableName); } /** * @param string $tableName * @param array $result * @return null|RuntimeException * @codeCoverageIgnore Car simple délégation */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result) { return $this->tableValidationHelper->convertSourceColumnsValidationBadResultToException($tableName, $result); } /** * @param SourceInterface $source * @return string Loading src/UnicaenDbImport/CodeGenerator/CodeGeneratorInterface.php +15 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,21 @@ interface CodeGeneratorInterface */ public function convertHistoColumnsValidationBadResultToException($tableName, array $result); /** * @param string $tableName * @return string * @codeCoverageIgnore Car simple délégation */ public function generateSQLForSourceColumnsValidation($tableName); /** * @param string $tableName * @param array $result * @return null|RuntimeException * @codeCoverageIgnore Car simple délégation */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result); /** * @param SourceInterface $source * @return string Loading src/UnicaenDbImport/CodeGenerator/Helper/DiffViewHelper.php +4 −1 Original line number Diff line number Diff line Loading @@ -174,9 +174,12 @@ with diff as ( $srcColumsSql, $destColumsSql $destColumsSql, s.source_id FROM $destinationTable d JOIN source src ON src.id = d.source_id AND src.synchronisable = 1 FULL OUTER JOIN $diffSourceTableName s ON s.$sourceCodeColumn = d.$sourceCodeColumn ) select * from diff Loading src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php +29 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,12 @@ abstract class TableValidationHelper extends Helper */ abstract public function generateSQLForHistoColumnsValidation($tableName); /** * @param string $tableName * @return string */ abstract public function generateSQLForSourceColumnsValidation($tableName); /** * @param string $tableName * @param array $result Loading @@ -79,6 +85,29 @@ abstract class TableValidationHelper extends Helper ALTER TABLE $tableName ADD created_on $timestamp DEFAULT $now NOT NULL ; ALTER TABLE $tableName ADD updated_on $timestamp ; ALTER TABLE $tableName ADD deleted_on $timestamp ; EOT; return new RuntimeException($message); } /** * @param string $tableName * @param array $result * @return null|RuntimeException */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result) { if (count($result) === 2) { return null; } $integer = $this->platform->getIntegerTypeDeclarationSQL([]); $varchar = $this->platform->getVarcharTypeDeclarationSQL([]); $message = "Assurez-vous que les colonnes suivantes sont présentes dans la table '$tableName' : " . PHP_EOL; $message .= <<<EOT ALTER TABLE $tableName ADD source_id $integer NOT NULL ; ALTER TABLE $tableName ADD source_code $varchar(100) ; EOT; return new RuntimeException($message); Loading src/UnicaenDbImport/CodeGenerator/PostgreSQL/Helper/TableValidationHelper.php +17 −6 Original line number Diff line number Diff line Loading @@ -55,10 +55,10 @@ EOT; WITH required_cols(column_name, column_type) AS ( $selects ) SELECT rc.column_name, c.udt_name SELECT rc.column_name, c.data_type FROM required_cols rc JOIN information_schema.columns c ON upper(c.column_name) = upper(rc.column_name) WHERE upper(c.table_name) = upper('$tableName') AND (rc.column_type IS NULL OR rc.column_type = c.udt_name) WHERE upper(c.table_name) = upper('$tableName') AND (rc.column_type IS NULL OR rc.column_type = c.data_type) ; EOT; return $sql; Loading @@ -69,12 +69,23 @@ EOT; */ public function generateSQLForHistoColumnsValidation($tableName) { $udtName = 'timestamp'; $columnsAndTypes = [ 'created_on' => 'timestamp without time zone', 'updated_on' => 'timestamp without time zone', 'deleted_on' => 'timestamp without time zone', ]; return $this->generateSQLForColumnsValidation($tableName, $columnsAndTypes); } /** * {@inheritDoc} */ public function generateSQLForSourceColumnsValidation($tableName) { $columnsAndTypes = [ 'created_on' => $udtName, 'updated_on' => $udtName, 'deleted_on' => $udtName, 'source_code' => 'character varying', 'source_id' => 'integer', ]; return $this->generateSQLForColumnsValidation($tableName, $columnsAndTypes); Loading Loading
src/UnicaenDbImport/CodeGenerator/CodeGenerator.php +21 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,27 @@ abstract class CodeGenerator implements CodeGeneratorInterface return $this->tableValidationHelper->convertHistoColumnsValidationBadResultToException($tableName, $result); } /** * @param string $tableName * @return string * @codeCoverageIgnore Car simple délégation */ public function generateSQLForSourceColumnsValidation($tableName) { return $this->tableValidationHelper->generateSQLForSourceColumnsValidation($tableName); } /** * @param string $tableName * @param array $result * @return null|RuntimeException * @codeCoverageIgnore Car simple délégation */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result) { return $this->tableValidationHelper->convertSourceColumnsValidationBadResultToException($tableName, $result); } /** * @param SourceInterface $source * @return string Loading
src/UnicaenDbImport/CodeGenerator/CodeGeneratorInterface.php +15 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,21 @@ interface CodeGeneratorInterface */ public function convertHistoColumnsValidationBadResultToException($tableName, array $result); /** * @param string $tableName * @return string * @codeCoverageIgnore Car simple délégation */ public function generateSQLForSourceColumnsValidation($tableName); /** * @param string $tableName * @param array $result * @return null|RuntimeException * @codeCoverageIgnore Car simple délégation */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result); /** * @param SourceInterface $source * @return string Loading
src/UnicaenDbImport/CodeGenerator/Helper/DiffViewHelper.php +4 −1 Original line number Diff line number Diff line Loading @@ -174,9 +174,12 @@ with diff as ( $srcColumsSql, $destColumsSql $destColumsSql, s.source_id FROM $destinationTable d JOIN source src ON src.id = d.source_id AND src.synchronisable = 1 FULL OUTER JOIN $diffSourceTableName s ON s.$sourceCodeColumn = d.$sourceCodeColumn ) select * from diff Loading
src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php +29 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,12 @@ abstract class TableValidationHelper extends Helper */ abstract public function generateSQLForHistoColumnsValidation($tableName); /** * @param string $tableName * @return string */ abstract public function generateSQLForSourceColumnsValidation($tableName); /** * @param string $tableName * @param array $result Loading @@ -79,6 +85,29 @@ abstract class TableValidationHelper extends Helper ALTER TABLE $tableName ADD created_on $timestamp DEFAULT $now NOT NULL ; ALTER TABLE $tableName ADD updated_on $timestamp ; ALTER TABLE $tableName ADD deleted_on $timestamp ; EOT; return new RuntimeException($message); } /** * @param string $tableName * @param array $result * @return null|RuntimeException */ public function convertSourceColumnsValidationBadResultToException($tableName, array $result) { if (count($result) === 2) { return null; } $integer = $this->platform->getIntegerTypeDeclarationSQL([]); $varchar = $this->platform->getVarcharTypeDeclarationSQL([]); $message = "Assurez-vous que les colonnes suivantes sont présentes dans la table '$tableName' : " . PHP_EOL; $message .= <<<EOT ALTER TABLE $tableName ADD source_id $integer NOT NULL ; ALTER TABLE $tableName ADD source_code $varchar(100) ; EOT; return new RuntimeException($message); Loading
src/UnicaenDbImport/CodeGenerator/PostgreSQL/Helper/TableValidationHelper.php +17 −6 Original line number Diff line number Diff line Loading @@ -55,10 +55,10 @@ EOT; WITH required_cols(column_name, column_type) AS ( $selects ) SELECT rc.column_name, c.udt_name SELECT rc.column_name, c.data_type FROM required_cols rc JOIN information_schema.columns c ON upper(c.column_name) = upper(rc.column_name) WHERE upper(c.table_name) = upper('$tableName') AND (rc.column_type IS NULL OR rc.column_type = c.udt_name) WHERE upper(c.table_name) = upper('$tableName') AND (rc.column_type IS NULL OR rc.column_type = c.data_type) ; EOT; return $sql; Loading @@ -69,12 +69,23 @@ EOT; */ public function generateSQLForHistoColumnsValidation($tableName) { $udtName = 'timestamp'; $columnsAndTypes = [ 'created_on' => 'timestamp without time zone', 'updated_on' => 'timestamp without time zone', 'deleted_on' => 'timestamp without time zone', ]; return $this->generateSQLForColumnsValidation($tableName, $columnsAndTypes); } /** * {@inheritDoc} */ public function generateSQLForSourceColumnsValidation($tableName) { $columnsAndTypes = [ 'created_on' => $udtName, 'updated_on' => $udtName, 'deleted_on' => $udtName, 'source_code' => 'character varying', 'source_id' => 'integer', ]; return $this->generateSQLForColumnsValidation($tableName, $columnsAndTypes); Loading