From 430c88c42f4d089dd9d26755fbeb7cdfe130773b Mon Sep 17 00:00:00 2001 From: Ivan Histand Date: Wed, 27 May 2026 12:22:19 -0500 Subject: [PATCH] =?UTF-8?q?refactor(postgres-adapter):=20relocate=20api/?= =?UTF-8?q?=20=E2=86=92=20cli/api/=20+=20update=20imports=20(Phase=202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 2 of `adapter/postgres-first-class` per docs/postgres_first_class_design.md (Phases 1-2 inherited verbatim from docs/postgres_reintegration_assessment.md). Moves the restored Postgres adapter files into the modern Dataform/sqlanvil CLI layout: api/dbadapters/postgres.ts → cli/api/dbadapters/postgres.ts api/utils/postgres.ts → cli/api/utils/postgres.ts Updated imports (mechanical) to point at the current `cli/api/...` modules: sa/api/commands/credentials → sa/cli/api/commands/credentials sa/api/dbadapters/index → sa/cli/api/dbadapters/index sa/api/utils/postgres → sa/cli/api/utils/postgres sa/api/utils/results → sa/cli/api/utils/results sa/core/adapters → sa/cli/api/dbadapters/execution_sql Also dropped the (now-broken) imports for symbols that were deleted upstream when non-BQ warehouses were removed: sa/api/ssh_tunnel_proxy — gone, deleted via commit b4d2b2f2 sa/api/utils/error_parsing — gone (parseRedshiftEvalError) The file still references `SSHTunnelProxy` and `parseRedshiftEvalError` in the body; that's fine — file is **excluded from the BUILD glob** in both `cli/api/BUILD` and `cli/api/utils/BUILD` until Phase 3 does the proper interface alignment (executeRaw, deleteTable, schemas signature, sqlanvil.IJDBC → new PostgresConnection proto, SSH removal, error formatter swap). Verified: ./scripts/docker-bazel build //... → 139 targets, success Empty root-level api/ directory removed. Next: Phase 3a — implement IDbAdapter against the relocated file. --- cli/api/BUILD | 5 +++++ {api => cli/api}/dbadapters/postgres.ts | 10 ++++------ cli/api/utils/BUILD | 8 +++++++- {api => cli/api}/utils/postgres.ts | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) rename {api => cli/api}/dbadapters/postgres.ts (95%) rename {api => cli/api}/utils/postgres.ts (98%) diff --git a/cli/api/BUILD b/cli/api/BUILD index ce1504de..91d1c969 100644 --- a/cli/api/BUILD +++ b/cli/api/BUILD @@ -11,6 +11,11 @@ ts_library( exclude = [ "utils/**/*.*", "**/*_test.ts", + # Postgres adapter — relocated from api/ in Phase 2. + # Excluded until Phase 3 (interface alignment + proto IJDBC → + # PostgresConnection rewrite) makes it compile against the + # current IDbAdapter contract. + "dbadapters/postgres.ts", ], ), deps = [ diff --git a/api/dbadapters/postgres.ts b/cli/api/dbadapters/postgres.ts similarity index 95% rename from api/dbadapters/postgres.ts rename to cli/api/dbadapters/postgres.ts index 541f005e..975b248a 100644 --- a/api/dbadapters/postgres.ts +++ b/cli/api/dbadapters/postgres.ts @@ -1,12 +1,10 @@ import * as pg from "pg"; -import { Credentials } from "sa/api/commands/credentials"; -import { IDbAdapter, IDbClient } from "sa/api/dbadapters/index"; -import { SSHTunnelProxy } from "sa/api/ssh_tunnel_proxy"; -import { parseRedshiftEvalError } from "sa/api/utils/error_parsing"; -import { convertFieldType, PgPoolExecutor } from "sa/api/utils/postgres"; +import { Credentials } from "sa/cli/api/commands/credentials"; +import { IDbAdapter, IDbClient } from "sa/cli/api/dbadapters/index"; +import { collectEvaluationQueries, QueryOrAction } from "sa/cli/api/dbadapters/execution_sql"; +import { convertFieldType, PgPoolExecutor } from "sa/cli/api/utils/postgres"; import { ErrorWithCause } from "sa/common/errors/errors"; -import { collectEvaluationQueries, QueryOrAction } from "sa/core/adapters"; import { sqlanvil } from "sa/protos/ts"; interface IPostgresAdapterOptions { diff --git a/cli/api/utils/BUILD b/cli/api/utils/BUILD index 42393bcd..8f68d608 100644 --- a/cli/api/utils/BUILD +++ b/cli/api/utils/BUILD @@ -4,7 +4,13 @@ load("//tools:ts_library.bzl", "ts_library") ts_library( name = "utils", - srcs = glob(["**/*.ts"]), + srcs = glob( + ["**/*.ts"], + # Postgres helper — relocated from api/utils/ in Phase 2. + # Excluded until Phase 3 wires it through cli/api's BUILD with + # the right pg/pg-query-stream deps and an updated import surface. + exclude = ["postgres.ts"], + ), deps = [ "//common/protos", "//common/strings", diff --git a/api/utils/postgres.ts b/cli/api/utils/postgres.ts similarity index 98% rename from api/utils/postgres.ts rename to cli/api/utils/postgres.ts index 79755e24..8d05ffe1 100644 --- a/api/utils/postgres.ts +++ b/cli/api/utils/postgres.ts @@ -1,7 +1,7 @@ import * as pg from "pg"; import QueryStream from "pg-query-stream"; -import { LimitedResultSet } from "sa/api/utils/results"; +import { LimitedResultSet } from "sa/cli/api/utils/results"; import { sqlanvil } from "sa/protos/ts"; const maybeInitializePg = (() => {