From 75b24425f19c15391f1b822f1c0d5fad1c34379f Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Thu, 26 Nov 2026 18:54:00 +0700 Subject: [PATCH 1/3] test(windows): live-server tests for PostgreSQL --- .github/workflows/windows.yml | 2 ++ windows/ci/live-servers.ps1 | 24 +++++++++++++++- .../Live/PostgresTests.cs | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2bd57d2cf0..688b69ac4f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -233,6 +233,8 @@ jobs: dotnet-version: 10.0.x - name: Start MySQL run: windows/ci/live-servers.ps1 -Server MySql + - name: Start PostgreSQL + run: windows/ci/live-servers.ps1 -Server Postgres - name: Start MongoDB run: windows/ci/live-servers.ps1 -Server MongoDb - name: Start Redis diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 index 56856fe8f3..e3ed978b5e 100644 --- a/windows/ci/live-servers.ps1 +++ b/windows/ci/live-servers.ps1 @@ -2,7 +2,7 @@ # TABLEPRO_TEST_LIVE__PORT, _USER and _PASSWORD. How each one runs: docs/decisions/0016-live-server-tests.md. param( [Parameter(Mandatory)] - [ValidateSet('MySql', 'SqlServer', 'MongoDb', 'Redis', 'Cassandra', 'Wsl', 'ClickHouse')] + [ValidateSet('MySql', 'SqlServer', 'MongoDb', 'Redis', 'Cassandra', 'Wsl', 'ClickHouse', 'Postgres')] [string]$Server ) @@ -72,6 +72,28 @@ switch ($Server) { if ($LASTEXITCODE -ne 0) { throw 'Creating the MySQL test user failed.' } Set-Live MYSQL 3306 tablepro $password } + # The image ships PostgreSQL in PGBIN as a stopped service, with superuser postgres and password root. + 'Postgres' { + if (-not $env:PGBIN -or -not (Test-Path (Join-Path $env:PGBIN 'psql.exe'))) { + throw 'The runner must provide PostgreSQL in PGBIN.' + } + $service = Get-Service 'postgresql-x64-*' | Select-Object -First 1 + Set-Service $service.Name -StartupType Manual + Start-Service $service.Name + $psql = Join-Path $env:PGBIN 'psql.exe' + $password = New-Password + $env:PGPASSWORD = 'root' + & $psql -h 127.0.0.1 -U postgres -d postgres -v ON_ERROR_STOP=1 ` + -c "CREATE ROLE tablepro LOGIN PASSWORD '$password'" ` + -c 'CREATE DATABASE tablepro OWNER tablepro' ` + -c "ALTER DATABASE tablepro SET timezone TO 'UTC'" + if ($LASTEXITCODE -ne 0) { throw 'Creating the PostgreSQL test database failed.' } + # The public schema's CREATE is not the database owner's on PostgreSQL 15 and later. + & $psql -h 127.0.0.1 -U postgres -d tablepro -v ON_ERROR_STOP=1 -c 'GRANT ALL ON SCHEMA public TO tablepro' + if ($LASTEXITCODE -ne 0) { throw 'Granting the PostgreSQL test schema failed.' } + Remove-Item Env:PGPASSWORD + Set-Live POSTGRES 5432 tablepro $password + } 'SqlServer' { $password = New-Password & (Join-Path $PSScriptRoot '../../core/crates/drivers/mssql/tests/windows/sql-server.ps1') -Install -SaPassword $password diff --git a/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs b/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs new file mode 100644 index 0000000000..5668579c78 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs @@ -0,0 +1,28 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class PostgresTests : SqlEngineTests +{ + private const string Database = "tablepro"; + private const string Schema = "public"; + + protected override string CorpusFile => "postgres"; + + protected override Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) + { + var server = LiveServer.Require("POSTGRES"); + return ConnectAsync( + core, + new SavedConnection(null, "PostgreSQL", "postgres", LiveServer.Host, server.Port, Database, server.UserName, new TlsSettings(TlsMode.Prefer)), + server.Secrets, + cancellationToken); + } + + protected override TableName Table(string name) => new(Schema, name); + + protected override string Qualified(string name) => $"\"{Schema}\".\"{name}\""; + + protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id integer PRIMARY KEY, label text NOT NULL)"; + + protected override string PeopleTableSql(string table) => + $"CREATE TABLE {table} (id integer PRIMARY KEY, name varchar(100) NOT NULL, note text)"; +} From a935c41de1ca211d8cfa8a7442566efda22d2672 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Thu, 26 Nov 2026 20:30:27 +0700 Subject: [PATCH 2/3] fix(windows): create the PostgreSQL test database as UTF8 --- windows/ci/live-servers.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 index e3ed978b5e..e835859316 100644 --- a/windows/ci/live-servers.ps1 +++ b/windows/ci/live-servers.ps1 @@ -83,9 +83,10 @@ switch ($Server) { $psql = Join-Path $env:PGBIN 'psql.exe' $password = New-Password $env:PGPASSWORD = 'root' + # template0 with UTF8: the cluster's own encoding on this image is not UTF8, and the value corpus is. & $psql -h 127.0.0.1 -U postgres -d postgres -v ON_ERROR_STOP=1 ` -c "CREATE ROLE tablepro LOGIN PASSWORD '$password'" ` - -c 'CREATE DATABASE tablepro OWNER tablepro' ` + -c 'CREATE DATABASE tablepro OWNER tablepro TEMPLATE template0 ENCODING ''UTF8'' LC_COLLATE ''C'' LC_CTYPE ''C''' ` -c "ALTER DATABASE tablepro SET timezone TO 'UTC'" if ($LASTEXITCODE -ne 0) { throw 'Creating the PostgreSQL test database failed.' } # The public schema's CREATE is not the database owner's on PostgreSQL 15 and later. From e1deb5b8a6341a117191884f3842ca6a59298e78 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Thu, 26 Nov 2026 20:50:56 +0700 Subject: [PATCH 3/3] fix(windows): set lc_monetary C so negative money matches the corpus --- windows/ci/live-servers.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 index e835859316..7552d81bce 100644 --- a/windows/ci/live-servers.ps1 +++ b/windows/ci/live-servers.ps1 @@ -84,10 +84,12 @@ switch ($Server) { $password = New-Password $env:PGPASSWORD = 'root' # template0 with UTF8: the cluster's own encoding on this image is not UTF8, and the value corpus is. + # lc_monetary C: the image's locale prints a negative money value in accounting parentheses, the corpus with a sign. & $psql -h 127.0.0.1 -U postgres -d postgres -v ON_ERROR_STOP=1 ` -c "CREATE ROLE tablepro LOGIN PASSWORD '$password'" ` -c 'CREATE DATABASE tablepro OWNER tablepro TEMPLATE template0 ENCODING ''UTF8'' LC_COLLATE ''C'' LC_CTYPE ''C''' ` - -c "ALTER DATABASE tablepro SET timezone TO 'UTC'" + -c "ALTER DATABASE tablepro SET timezone TO 'UTC'" ` + -c "ALTER DATABASE tablepro SET lc_monetary TO 'C'" if ($LASTEXITCODE -ne 0) { throw 'Creating the PostgreSQL test database failed.' } # The public schema's CREATE is not the database owner's on PostgreSQL 15 and later. & $psql -h 127.0.0.1 -U postgres -d tablepro -v ON_ERROR_STOP=1 -c 'GRANT ALL ON SCHEMA public TO tablepro'