@@ -178,5 +178,93 @@ protected override void Up(MigrationBuilder migrationBuilder)
178178 Assert . Equal ( final , str , ignoreLineEndingDifferences : true ) ;
179179 }
180180
181+
182+ [ Fact ]
183+ public void ShouldReplaceSchemaInForeignKeyTableConstraint ( )
184+ {
185+ var classString = @"
186+ public partial class AddUserName : Migration
187+ {
188+
189+ /// <inheritdoc />
190+ protected override void Up(MigrationBuilder migrationBuilder)
191+ {
192+ migrationBuilder.CreateTable(
193+ name: ""OrganizationUser"",
194+ schema: _schema.Schema,
195+ columns: table => new
196+ {
197+ OrganizationsId = table.Column<string>(type: ""text"", nullable: false),
198+ UsersId = table.Column<string>(type: ""text"", nullable: false)
199+ },
200+ constraints: table =>
201+ {
202+ table.PrimaryKey(""PK_OrganizationUser"", x => new { x.OrganizationsId, x.UsersId });
203+ table.ForeignKey(
204+ name: ""FK_OrganizationUser_Organization_OrganizationsId"",
205+ column: x => x.OrganizationsId,
206+ principalSchema: ""defaultSchema"",
207+ principalTable: ""Organization"",
208+ principalColumn: ""Id"",
209+ onDelete: ReferentialAction.Cascade);
210+ table.ForeignKey(
211+ name: ""FK_OrganizationUser_Users_UsersId"",
212+ column: x => x.UsersId,
213+ principalSchema: ""defaultSchema"",
214+ principalTable: ""Users"",
215+ principalColumn: ""Id"",
216+ onDelete: ReferentialAction.Cascade);
217+ });
218+ }" ;
219+
220+ var final = @"
221+ public partial class AddUserName : Migration
222+ {
223+ private readonly InterfaceName _schema;
224+
225+ /// <inheritdoc />
226+ public AddUserName(InterfaceName schema)
227+ {
228+ _schema = schema;
229+ }
230+
231+ /// <inheritdoc />
232+ protected override void Up(MigrationBuilder migrationBuilder)
233+ {
234+ migrationBuilder.CreateTable(
235+ name: ""OrganizationUser"",
236+ schema: _schema.Schema,
237+ columns: table => new
238+ {
239+ OrganizationsId = table.Column<string>(type: ""text"", nullable: false),
240+ UsersId = table.Column<string>(type: ""text"", nullable: false)
241+ },
242+ constraints: table =>
243+ {
244+ table.PrimaryKey(""PK_OrganizationUser"", x => new { x.OrganizationsId, x.UsersId });
245+ table.ForeignKey(
246+ name: ""FK_OrganizationUser_Organization_OrganizationsId"",
247+ column: x => x.OrganizationsId,
248+ principalSchema: _schema.Schema,
249+ principalTable: ""Organization"",
250+ principalColumn: ""Id"",
251+ onDelete: ReferentialAction.Cascade);
252+ table.ForeignKey(
253+ name: ""FK_OrganizationUser_Users_UsersId"",
254+ column: x => x.UsersId,
255+ principalSchema: _schema.Schema,
256+ principalTable: ""Users"",
257+ principalColumn: ""Id"",
258+ onDelete: ReferentialAction.Cascade);
259+ });
260+ }" ;
261+
262+ var result = MigrationCommand . RewriteSyntaxtNode ( interfaceName , "testPath" , classString ) ;
263+ var str = result . ToFullString ( ) ;
264+
265+ Assert . Equal ( final , str , ignoreLineEndingDifferences : true ) ;
266+ }
267+
268+
181269 }
182270}
0 commit comments