Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.300" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="10.0.3" />
<PackageVersion Include="NSchema.Core" Version="3.0.0-alpha.41" />
<PackageVersion Include="NSchema.Core" Version="3.0.0-alpha.42" />
<PackageVersion Include="Testcontainers" Version="4.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageVersion Include="Npgsql" Version="10.0.3" />
Expand Down
2 changes: 1 addition & 1 deletion src/NSchema.Postgres/NSchema.Postgres.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>3.0.0-alpha.12</Version>
<Version>3.0.0-beta.1</Version>
<AssemblyVersion>$(Version.Split('-')[0])</AssemblyVersion>
<FileVersion>$(Version.Split('-')[0])</FileVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
4 changes: 2 additions & 2 deletions src/NSchema.Postgres/Sql/PostgresSchemaProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ private static async Task<List<ColumnRow>> QueryColumns(NpgsqlConnection conn, s
seq.seqincrement AS identity_increment,
CASE WHEN c.is_generated = 'ALWAYS' THEN c.generation_expression END AS generation_expression
FROM information_schema.columns c
LEFT JOIN pg_namespace n ON n.nspname = c.table_schema
LEFT JOIN pg_class t ON t.relname = c.table_name
AND t.relnamespace = n.oid
AND t.relkind = 'r'
LEFT JOIN pg_namespace n ON n.oid = t.relnamespace
AND n.nspname = c.table_schema
LEFT JOIN pg_attribute a ON a.attrelid = t.oid
AND a.attname = c.column_name
LEFT JOIN pg_depend d ON d.refobjid = t.oid
Expand Down
41 changes: 41 additions & 0 deletions tests/NSchema.Postgres.Tests/Sql/PostgresSchemaProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,4 +1042,45 @@ public async Task GetSchema_Extensions_AreReportedAtRootWithVersion()
citext.Version.ShouldNotBeNull();
schema.Extensions.ShouldNotContain(e => e.Name == "plpgsql");
}

// ── Same table name across schemas ────────────────────────────────────────

// Regression: the columns query joined pg_class on relname alone (not namespace), so a table name shared by
// two schemas matched both pg_class rows and fanned every column row out once per schema — columns appeared
// duplicated in each table. Each table must report only its own columns.
[Fact]
public async Task GetSchema_SameTableNameInDifferentSchemas_DoesNotDuplicateColumns()
{
// Arrange
var other = $"test_{Guid.NewGuid():N}";
await Exec($"CREATE SCHEMA \"{other}\"");
try
{
await Exec($"""
CREATE TABLE "{_schema}".users (
id INTEGER NOT NULL,
name TEXT NOT NULL
)
""");
await Exec($"""
CREATE TABLE "{other}".users (
code INTEGER NOT NULL,
region TEXT NOT NULL
)
""");

// Act
var model = await _sut.GetSchema([_schema, other], TestContext.Current.CancellationToken);

// Assert
var primary = model.Schemas.Single(s => s.Name == _schema).Tables.Single(t => t.Name == "users");
var secondary = model.Schemas.Single(s => s.Name == other).Tables.Single(t => t.Name == "users");
primary.Columns.Select(c => c.Name).ShouldBe(["id", "name"]);
secondary.Columns.Select(c => c.Name).ShouldBe(["code", "region"]);
}
finally
{
await Exec($"DROP SCHEMA IF EXISTS \"{other}\" CASCADE");
}
}
}