@@ -50,14 +50,16 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
5050 $ schema = $ schemaClosure ();
5151
5252 if (!$ schema ->hasTable ('sharing_classmap ' )) {
53- $ table = $ schema ->createTable ('sharing_classmap ' );
54- $ table ->addColumn ('class_id ' , Types::INTEGER , [
53+ $ mappingTable = $ schema ->createTable ('sharing_classmap ' );
54+ $ mappingTable ->addColumn ('class_id ' , Types::INTEGER , [
5555 'autoincrement ' => true ,
5656 'notnull ' => true ,
5757 ]);
58- $ table ->addColumn ('class_name ' , Types::STRING , ['length ' => 64 ]);
59- $ table ->setPrimaryKey (['class_id ' ]);
60- $ table ->addUniqueIndex (['class_name ' ]);
58+ $ mappingTable ->addColumn ('class_name ' , Types::STRING , ['length ' => 64 ]);
59+ $ mappingTable ->setPrimaryKey (['class_id ' ]);
60+ $ mappingTable ->addUniqueIndex (['class_name ' ]);
61+ } else {
62+ $ mappingTable = $ schema ->getTable ('sharing_classmap ' );
6163 }
6264
6365 $ sourcesTable = $ schema ->getTable ('sharing_share_sources ' );
@@ -66,7 +68,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6668 $ sourcesTable ->addColumn ('source_class_id ' , Types::INTEGER );
6769 $ sourcesTable ->dropPrimaryKey ();
6870 $ sourcesTable ->setPrimaryKey (['share_id ' , 'source_class_id ' , 'source_value ' ]);
69- $ sourcesTable ->addForeignKeyConstraint (' sharing_classmap ' , ['source_class_id ' ], ['class_id ' ]);
71+ $ sourcesTable ->addForeignKeyConstraint ($ mappingTable -> getName () , ['source_class_id ' ], ['class_id ' ]);
7072 }
7173
7274 $ recipientsTable = $ schema ->getTable ('sharing_share_recipients ' );
@@ -75,7 +77,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
7577 $ recipientsTable ->addColumn ('recipient_class_id ' , Types::INTEGER );
7678 $ recipientsTable ->dropPrimaryKey ();
7779 $ recipientsTable ->setPrimaryKey (['share_id ' , 'recipient_class_id ' , 'recipient_value ' ]);
78- $ recipientsTable ->addForeignKeyConstraint (' sharing_classmap ' , ['recipient_class_id ' ], ['class_id ' ]);
80+ $ recipientsTable ->addForeignKeyConstraint ($ mappingTable -> getName () , ['recipient_class_id ' ], ['class_id ' ]);
7981 }
8082
8183 $ propertiesTable = $ schema ->getTable ('sharing_share_properties ' );
@@ -84,7 +86,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
8486 $ propertiesTable ->addColumn ('property_class_id ' , Types::INTEGER );
8587 $ propertiesTable ->dropPrimaryKey ();
8688 $ propertiesTable ->setPrimaryKey (['share_id ' , 'property_class_id ' ]);
87- $ propertiesTable ->addForeignKeyConstraint (' sharing_classmap ' , ['property_class_id ' ], ['class_id ' ]);
89+ $ propertiesTable ->addForeignKeyConstraint ($ mappingTable -> getName () , ['property_class_id ' ], ['class_id ' ]);
8890 }
8991
9092 $ permissionsTable = $ schema ->getTable ('sharing_share_permissions ' );
@@ -93,7 +95,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
9395 $ permissionsTable ->addColumn ('permission_class_id ' , Types::INTEGER );
9496 $ permissionsTable ->dropPrimaryKey ();
9597 $ permissionsTable ->setPrimaryKey (['share_id ' , 'permission_class_id ' ]);
96- $ permissionsTable ->addForeignKeyConstraint (' sharing_classmap ' , ['permission_class_id ' ], ['class_id ' ]);
98+ $ permissionsTable ->addForeignKeyConstraint ($ mappingTable -> getName () , ['permission_class_id ' ], ['class_id ' ]);
9799 }
98100
99101 return $ schema ;
0 commit comments