66use Intanode \UgLocale \Services \LocaleService ;
77use Intanode \UgLocale \Models \{District , County , SubCounty , Parish , Village , Region };
88use Illuminate \Support \Facades \{Artisan , DB , Schema , Log };
9+ use Illuminate \Support \Facades \Schema ;
910
1011class TransformAndSeedLocale extends Command
1112{
@@ -112,6 +113,16 @@ private function seedTable(string $name, string $modelClass, callable $transform
112113 $ this ->info ("📊 Total $ name records: $ totalRecords " );
113114
114115 DB ::transaction (function () use ($ modelClass , $ data , $ batchSize , $ name , $ totalRecords ) {
116+
117+ $ driver = Schema::getConnection ()->getDriverName ();
118+
119+ $ table = (new $ modelClass )->getTable ();
120+
121+ if ($ driver === 'sqlsrv ' ) {
122+ DB ::statement ("SET IDENTITY_INSERT {$ table } ON " );
123+ }
124+
125+
115126 if ($ batchSize ) {
116127 $ chunks = array_chunk ($ data , $ batchSize );
117128 $ this ->output ->progressStart (count ($ chunks ));
@@ -130,6 +141,11 @@ private function seedTable(string $name, string $modelClass, callable $transform
130141 }
131142 $ this ->output ->progressFinish ();
132143 }
144+
145+ if ($ driver === 'sqlsrv ' ) {
146+ DB ::statement ("SET IDENTITY_INSERT {$ table } OFF " );
147+ }
148+
133149 });
134150
135151 $ this ->info ("✅ $ name have been successfully seeded! " );
0 commit comments