@@ -59,6 +59,28 @@ public function __construct(
59
59
$ this ->operationsExecutor = $ operationsExecutor ;
60
60
}
61
61
62
+ /**
63
+ * Create consistent table index from all tables
64
+ *
65
+ * All declared table names should have order, all tables exists only in db should goes after them
66
+ *
67
+ * @param array $tableNames
68
+ * @param array $generatedTableNames
69
+ * @return array
70
+ */
71
+ private function createTableIndex (array $ tableNames , array $ generatedTableNames )
72
+ {
73
+ $ tableNames = array_flip ($ tableNames );
74
+ foreach ($ generatedTableNames as $ tableName ) {
75
+ //If table exists only in db
76
+ if (!isset ($ tableNames [$ tableName ])) {
77
+ array_push ($ tableNames , $ tableName );
78
+ }
79
+ }
80
+
81
+ return $ tableNames ;
82
+ }
83
+
62
84
/**
63
85
* Create diff.
64
86
*
@@ -71,10 +93,12 @@ public function diff(
71
93
Schema $ generatedSchema
72
94
) {
73
95
$ generatedTables = $ generatedSchema ->getTables ();
74
- $ tableIndex = array_flip (array_keys ($ schema ->getTables ()));
96
+ $ tableNames = array_keys ($ schema ->getTables ());
97
+ $ generatedTableNames = array_keys ($ generatedSchema ->getTables ());
98
+
75
99
$ diff = $ this ->diffFactory ->create (
76
100
[
77
- 'tableIndexes ' => $ tableIndex ,
101
+ 'tableIndexes ' => $ this -> createTableIndex ( $ tableNames , $ generatedTableNames ) ,
78
102
'destructiveOperations ' => $ this ->operationsExecutor ->getDestructiveOperations ()
79
103
]
80
104
);
0 commit comments