@@ -140,9 +140,13 @@ private function createMultiLangField($translationKey)
140140 private function installDatabase ()
141141 {
142142 $ sql = [];
143+ // DB migrations do not work with PACKETERY_REMOVE_ALL_DATA set to false
144+ $ dropTables = !defined ('PACKETERY_REMOVE_ALL_DATA ' ) || PACKETERY_REMOVE_ALL_DATA ;
143145
144- $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_order` ' ;
145- $ sql [] = 'CREATE TABLE ` ' . _DB_PREFIX_ . 'packetery_order` (
146+ if ($ dropTables ) {
147+ $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_order` ' ;
148+ }
149+ $ sql [] = 'CREATE TABLE IF NOT EXISTS ` ' . _DB_PREFIX_ . 'packetery_order` (
146150 `id_order` int,
147151 `id_cart` int,
148152 `id_branch` int NULL,
@@ -173,14 +177,18 @@ private function installDatabase()
173177 UNIQUE(`id_cart`)
174178 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ' ;
175179
176- $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_payment` ' ;
177- $ sql [] = 'CREATE TABLE ` ' . _DB_PREFIX_ . 'packetery_payment` (
180+ if ($ dropTables ) {
181+ $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_payment` ' ;
182+ }
183+ $ sql [] = 'CREATE TABLE IF NOT EXISTS ` ' . _DB_PREFIX_ . 'packetery_payment` (
178184 `module_name` varchar(255) NOT NULL PRIMARY KEY,
179185 `is_cod` tinyint(1) NOT NULL DEFAULT 0
180186 ) ENGINE=InnoDB DEFAULT charset=utf8; ' ;
181187
182- $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_address_delivery` ' ;
183- $ sql [] = 'CREATE TABLE ` ' . _DB_PREFIX_ . 'packetery_address_delivery` (
188+ if ($ dropTables ) {
189+ $ sql [] = 'DROP TABLE IF EXISTS ` ' . _DB_PREFIX_ . 'packetery_address_delivery` ' ;
190+ }
191+ $ sql [] = 'CREATE TABLE IF NOT EXISTS ` ' . _DB_PREFIX_ . 'packetery_address_delivery` (
184192 `id_carrier` int NOT NULL PRIMARY KEY,
185193 `id_branch` varchar(255) NOT NULL,
186194 `name_branch` varchar(255) NULL,
@@ -192,19 +200,27 @@ private function installDatabase()
192200 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ' ;
193201
194202 $ productAttributeRepository = $ this ->module ->diContainer ->get (ProductAttributeRepository::class);
195- $ sql [] = $ productAttributeRepository ->getDropTableSql ();
203+ if ($ dropTables ) {
204+ $ sql [] = $ productAttributeRepository ->getDropTableSql ();
205+ }
196206 $ sql [] = $ productAttributeRepository ->getCreateTableSql ();
197207
198208 $ apiCarrierRepository = $ this ->module ->diContainer ->get (ApiCarrierRepository::class);
199- $ sql [] = $ apiCarrierRepository ->getDropTableSql ();
209+ if ($ dropTables ) {
210+ $ sql [] = $ apiCarrierRepository ->getDropTableSql ();
211+ }
200212 $ sql [] = $ apiCarrierRepository ->getCreateTableSql ();
201213
202214 $ logRepository = $ this ->module ->diContainer ->get (LogRepository::class);
203- $ sql [] = $ logRepository ->getDropTableSql ();
215+ if ($ dropTables ) {
216+ $ sql [] = $ logRepository ->getDropTableSql ();
217+ }
204218 $ sql [] = $ logRepository ->getCreateTableSql ();
205219
206220 $ packetTrackingRepository = $ this ->module ->diContainer ->get (PacketTrackingRepository::class);
207- $ sql [] = $ packetTrackingRepository ->getDropTableSql ();
221+ if ($ dropTables ) {
222+ $ sql [] = $ packetTrackingRepository ->getDropTableSql ();
223+ }
208224 $ sql [] = $ packetTrackingRepository ->getCreateTableSql ();
209225
210226 if (!$ this ->dbTools ->executeQueries ($ sql , $ this ->getExceptionRaisedText (), true )) {
0 commit comments