diff --git a/Directory.Packages.props b/Directory.Packages.props
index 941e651..beac33f 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -7,7 +7,7 @@
-
+
diff --git a/src/NSchema.Postgres/NSchema.Postgres.csproj b/src/NSchema.Postgres/NSchema.Postgres.csproj
index 5935bc6..339ed5d 100644
--- a/src/NSchema.Postgres/NSchema.Postgres.csproj
+++ b/src/NSchema.Postgres/NSchema.Postgres.csproj
@@ -20,7 +20,7 @@
true
true
snupkg
- 5.0.0-alpha.5
+ 5.0.0-alpha.6
$(Version.Split('-')[0])
$(Version.Split('-')[0])
true
diff --git a/src/NSchema.Postgres/PostgresPlugin.cs b/src/NSchema.Postgres/PostgresPlugin.cs
index 991febf..0ce1369 100644
--- a/src/NSchema.Postgres/PostgresPlugin.cs
+++ b/src/NSchema.Postgres/PostgresPlugin.cs
@@ -1,5 +1,9 @@
using NSchema.Configuration.Plugins;
using NSchema.Plugins;
+using NSchema.Project.Nsql;
+using NSchema.Project.Nsql.Syntax;
+using NSchema.Project.Nsql.Syntax.Blocks;
+using NSchema.Project.Nsql.Tokens;
namespace NSchema.Postgres;
@@ -24,17 +28,20 @@ private sealed class PostgresOptions
}
///
- public string GetScaffoldTemplate(ScaffoldContext context) =>
- $"""
- DATABASE postgres (
- -- Prefer the {EnvConnectionString} environment variable, which
- -- overrides the value below.
- connection_string = ''
- -- Credentials may be supplied separately from the connection string (e.g. from
- -- a secret store) via {EnvUsername} / {EnvPassword}.
- -- They override any user/password embedded in connection_string.
- );
- """;
+ public BlockStatement GetScaffoldTemplate(ScaffoldContext context) =>
+ new(BlockKeyword.Database, Identifier.Synthetic("postgres"), new SeparatedSyntaxList(
+ [
+ new BlockAttribute("connection_string", string.Empty),
+ ]))
+ {
+ DocComment = new Token(
+ TokenKind.DocComment,
+ $"Prefer the {EnvConnectionString} environment variable, which overrides the value below.\n" +
+ $"Credentials may be supplied separately from the connection string (e.g. from a secret\n" +
+ $"store) via {EnvUsername} / {EnvPassword}. They override any user/password embedded in\n" +
+ "connection_string.",
+ SourcePosition.None),
+ };
///
public string GetSampleSchema() =>
diff --git a/src/NSchema.Postgres/Sql/PostgresDatabaseIntrospector.cs b/src/NSchema.Postgres/Sql/PostgresDatabaseIntrospector.cs
index 4cfa37f..2ca17c8 100644
--- a/src/NSchema.Postgres/Sql/PostgresDatabaseIntrospector.cs
+++ b/src/NSchema.Postgres/Sql/PostgresDatabaseIntrospector.cs
@@ -26,7 +26,10 @@ public async ValueTask GetDatabase(PlanningScope scope, CancellationTo
await using var conn = await dataSource.OpenConnectionAsync(cancellationToken);
// The scope is a hint; null means "all visible schemas" and the engine re-applies the scope after the read.
- var schemas = scope.IsUnscoped ? null : scope.SchemaNames.Select(s => s.Value).ToArray();
+ // Every address belongs to a schema (a schema address is its own), so the read narrows to those.
+ var schemas = scope.IsUnscoped
+ ? null
+ : scope.Addresses.Select(a => a.SchemaName).OfType().Distinct().Select(s => s.Value).ToArray();
var tables = await QueryTables(conn, schemas, cancellationToken);
var columns = await QueryColumns(conn, schemas, cancellationToken);
diff --git a/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs b/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs
index 028eed6..979500c 100644
--- a/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs
+++ b/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs
@@ -168,7 +168,7 @@ private NSchemaApplication BuildApp()
private async Task Introspect() =>
await new PostgresDatabaseIntrospector(_fixture.DataSource)
- .GetDatabase(PlanningScope.To([new SqlIdentifier(_schema)]), TestContext.Current.CancellationToken);
+ .GetDatabase(PlanningScope.To(new SchemaAddress(_schema)), TestContext.Current.CancellationToken);
private async Task Exec(string sql)
{
diff --git a/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs b/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs
index e3ff10f..cc7146c 100644
--- a/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs
+++ b/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs
@@ -1,6 +1,7 @@
using NSchema.Configuration.Plugins;
using NSchema.Plan.Backends;
using NSchema.Plugins;
+using NSchema.Project.Nsql.Syntax.Blocks;
namespace NSchema.Postgres.Tests;
@@ -41,7 +42,13 @@ public void Dispose()
[Fact]
public void GetScaffoldTemplate_ReturnsDatabaseStatement()
- => _sut.GetScaffoldTemplate(new ScaffoldContext()).ShouldContain("DATABASE postgres");
+ {
+ var block = _sut.GetScaffoldTemplate(new ScaffoldContext());
+
+ block.Keyword.ShouldBe(BlockKeyword.Database);
+ block.Label!.Value.ShouldBe("postgres");
+ block.Attributes.ShouldContain(a => a.Key == "connection_string");
+ }
[Fact]
public void GetSampleSchema_ScaffoldsANamedSchema()
diff --git a/tests/NSchema.Postgres.Tests/Sql/PostgresDatabaseIntrospectorTests.cs b/tests/NSchema.Postgres.Tests/Sql/PostgresDatabaseIntrospectorTests.cs
index 53fdeb3..68811f2 100644
--- a/tests/NSchema.Postgres.Tests/Sql/PostgresDatabaseIntrospectorTests.cs
+++ b/tests/NSchema.Postgres.Tests/Sql/PostgresDatabaseIntrospectorTests.cs
@@ -39,7 +39,7 @@ private async Task Exec(string sql)
/// Reads the live schema scoped to the given schema names.
private async Task Introspect(params string[] schemas) =>
- await _sut.GetDatabase(PlanningScope.To(schemas.Select(s => new SqlIdentifier(s))), TestContext.Current.CancellationToken);
+ await _sut.GetDatabase(PlanningScope.To(schemas.Select(s => new SchemaAddress(s))), TestContext.Current.CancellationToken);
// ── Schema / table structure ──────────────────────────────────────────────
diff --git a/tests/NSchema.Postgres.Tests/Sql/PostgresSqlDialectTests.cs b/tests/NSchema.Postgres.Tests/Sql/PostgresSqlDialectTests.cs
index d0eba9f..e741b50 100644
--- a/tests/NSchema.Postgres.Tests/Sql/PostgresSqlDialectTests.cs
+++ b/tests/NSchema.Postgres.Tests/Sql/PostgresSqlDialectTests.cs
@@ -1457,7 +1457,7 @@ private async Task Run(params MigrationAction[] actions)
private async Task Introspect() =>
await new PostgresDatabaseIntrospector(_dataSource)
- .GetDatabase(PlanningScope.To([new SqlIdentifier(_schema)]), TestContext.Current.CancellationToken);
+ .GetDatabase(PlanningScope.To(new SchemaAddress(_schema)), TestContext.Current.CancellationToken);
private async Task Exec(string sql)
{