diff --git a/ef-migration-runtimeschema.Tests/RewriteTest.cs b/ef-migration-runtimeschema.Tests/RewriteTest.cs
index 4f418c1..90ad400 100644
--- a/ef-migration-runtimeschema.Tests/RewriteTest.cs
+++ b/ef-migration-runtimeschema.Tests/RewriteTest.cs
@@ -178,5 +178,93 @@ protected override void Up(MigrationBuilder migrationBuilder)
Assert.Equal(final, str, ignoreLineEndingDifferences: true);
}
+
+ [Fact]
+ public void ShouldReplaceSchemaInForeignKeyTableConstraint()
+ {
+ var classString = @"
+public partial class AddUserName : Migration
+{
+
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: ""OrganizationUser"",
+ schema: _schema.Schema,
+ columns: table => new
+ {
+ OrganizationsId = table.Column(type: ""text"", nullable: false),
+ UsersId = table.Column(type: ""text"", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey(""PK_OrganizationUser"", x => new { x.OrganizationsId, x.UsersId });
+ table.ForeignKey(
+ name: ""FK_OrganizationUser_Organization_OrganizationsId"",
+ column: x => x.OrganizationsId,
+ principalSchema: ""defaultSchema"",
+ principalTable: ""Organization"",
+ principalColumn: ""Id"",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: ""FK_OrganizationUser_Users_UsersId"",
+ column: x => x.UsersId,
+ principalSchema: ""defaultSchema"",
+ principalTable: ""Users"",
+ principalColumn: ""Id"",
+ onDelete: ReferentialAction.Cascade);
+ });
+}";
+
+ var final = @"
+public partial class AddUserName : Migration
+{
+ private readonly InterfaceName _schema;
+
+ ///
+ public AddUserName(InterfaceName schema)
+ {
+ _schema = schema;
+ }
+
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: ""OrganizationUser"",
+ schema: _schema.Schema,
+ columns: table => new
+ {
+ OrganizationsId = table.Column(type: ""text"", nullable: false),
+ UsersId = table.Column(type: ""text"", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey(""PK_OrganizationUser"", x => new { x.OrganizationsId, x.UsersId });
+ table.ForeignKey(
+ name: ""FK_OrganizationUser_Organization_OrganizationsId"",
+ column: x => x.OrganizationsId,
+ principalSchema: _schema.Schema,
+ principalTable: ""Organization"",
+ principalColumn: ""Id"",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: ""FK_OrganizationUser_Users_UsersId"",
+ column: x => x.UsersId,
+ principalSchema: _schema.Schema,
+ principalTable: ""Users"",
+ principalColumn: ""Id"",
+ onDelete: ReferentialAction.Cascade);
+ });
+}";
+
+ var result = MigrationCommand.RewriteSyntaxtNode(interfaceName, "testPath", classString);
+ var str = result.ToFullString();
+
+ Assert.Equal(final, str, ignoreLineEndingDifferences: true);
+ }
+
+
}
}
\ No newline at end of file
diff --git a/src/ef-migration-runtimeschema/SchemaRewriter.cs b/src/ef-migration-runtimeschema/SchemaRewriter.cs
index 8809cc5..b1d5890 100644
--- a/src/ef-migration-runtimeschema/SchemaRewriter.cs
+++ b/src/ef-migration-runtimeschema/SchemaRewriter.cs
@@ -13,6 +13,9 @@ public class SchemaRewriter : CSharpSyntaxRewriter
if (node.NameColon?.Name.Identifier.Text == "schema")
return CreateSchemaRefnode(node);
+ if (node.NameColon?.Name.Identifier.Text == "principalSchema")
+ return CreateSchemaRefnode(node);
+
//Replace Schema Name for migrationBuilder.EnsureSchema()
if (node.NameColon?.Name.Identifier.Text == "name"
diff --git a/src/ef-migration-runtimeschema/ef-migration-runtime-schema.csproj b/src/ef-migration-runtimeschema/ef-migration-runtime-schema.csproj
index 5b4c51b..fd45034 100644
--- a/src/ef-migration-runtimeschema/ef-migration-runtime-schema.csproj
+++ b/src/ef-migration-runtimeschema/ef-migration-runtime-schema.csproj
@@ -22,7 +22,7 @@
efcore cli
https://github.com/jdevillard/ef-migration-runtime-schema
https://github.com/jdevillard/ef-migration-runtime-schema
- 1.0.1
+ 1.0.2