[GH-ISSUE #101] I add some code for create full field name when create the db migrations #72

Open
opened 2026-02-25 21:33:11 +03:00 by kerem · 0 comments
Owner

Originally created by @kmdaliu on GitHub (Sep 22, 2020).
Original GitHub issue: https://github.com/DBDiff/DBDiff/issues/101

I found the migrations sql statements is simple format ,like this:

### SQL_DOWN = u"""
INSERT INTO `cms_column`  VALUES('1','0','cloum_name ','1','','_self','','','','','','0','1578624289','1578624289','100','1','0','0','0','0');
"""

if the source table field's sequence if different to the target table, the created migrations will can't insert into table rightly , the two table fields are name and type are same even if it is. because the "sequence" is defferent , so the data is wrong.

for this bug.
I add some code for create full field name when create the db migrations. like this:
for two files:
1.DBDiff-master\src\SQLGen\DiffToSQL\DeleteDataSQL.php
( getDown() ----------in this function )
2.DBDiff-master\src\SQLGen\DiffToSQL\InsertDataSQL.php
( getUp() ----------in this function )

 //---- by daliu start ---
       $params = ParamsFactory::get();
       $this->manager = new DBManager;
       $this->manager->connect($params);
       $tableSchema = new TableSchema($this->manager);
       $schemas = $tableSchema->getSchema('target', $table);
       return "INSERT INTO `$table` (" .implode(',', array_keys($schemas['columns'])). ") VALUES(".implode(',', $values).");";
       //---- by daliu  end  ---

and you need to add the following code to the two files above :

use DBDiff\DB\DBManager;
use DBDiff\DB\Schema\TableSchema;
use DBDiff\Params\ParamsFactory;

i wish this will can help to peoples who be plagued by this problem.

my english is very weak, I hope you understand.

thanks DBDiff.

Originally created by @kmdaliu on GitHub (Sep 22, 2020). Original GitHub issue: https://github.com/DBDiff/DBDiff/issues/101 I found the migrations sql statements is simple format ,like this: ``` ### SQL_DOWN = u""" INSERT INTO `cms_column` VALUES('1','0','cloum_name ','1','','_self','','','','','','0','1578624289','1578624289','100','1','0','0','0','0'); """ ``` if the source table field's sequence if different to the target table, the created migrations will can't insert into table rightly , the two table fields are name and type are same even if it is. because the "sequence" is defferent , so the data is wrong. for this bug. I add some code for create full field name when create the db migrations. like this: for two files: 1.DBDiff-master\src\SQLGen\DiffToSQL\DeleteDataSQL.php ( getDown() ----------in this function ) 2.DBDiff-master\src\SQLGen\DiffToSQL\InsertDataSQL.php ( getUp() ----------in this function ) ``` //---- by daliu start --- $params = ParamsFactory::get(); $this->manager = new DBManager; $this->manager->connect($params); $tableSchema = new TableSchema($this->manager); $schemas = $tableSchema->getSchema('target', $table); return "INSERT INTO `$table` (" .implode(',', array_keys($schemas['columns'])). ") VALUES(".implode(',', $values).");"; //---- by daliu end --- ``` and you need to add the following code to the two files above : ``` use DBDiff\DB\DBManager; use DBDiff\DB\Schema\TableSchema; use DBDiff\Params\ParamsFactory; ``` i wish this will can help to peoples who be plagued by this problem. my english is very weak, I hope you understand. thanks DBDiff.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/DBDiff#72
No description provided.